How to turn on WCF tracing?
Asked Answered
A

4

166

Update:

I have been trying to turn on WCF tracing, but still no success... Below is my lastest update.

Do I need a permission to write to the below location?

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "@\\myservername\folder1\traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

I am using .NET Framework 3.5.

What is the step-by-step instruction to turn on the WCF tracking for debugging purposes?

Attired answered 24/11, 2010 at 21:1 Comment(0)
P
235

The following configuration taken from MSDN can be applied to enable tracing on your WCF service.

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
             <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
            <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="Information, ActivityTracing">
        <listeners>
            <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
        <add name="xml"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData="Error.svclog" />
    </sharedListeners>
  </system.diagnostics>
</configuration>

To view the log file, you can use "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\SvcTraceViewer.exe".

If "SvcTraceViewer.exe" is not on your system, you can download it from the "Microsoft Windows SDK for Windows 7 and .NET Framework 4" package here:

Windows SDK Download

You don't have to install the entire thing, just the ".NET Development / Tools" part.

When/if it bombs out during installation with a non-sensical error, Petopas' answer to Windows 7 SDK Installation Failure solved my issue.

Proserpina answered 24/11, 2010 at 21:11 Comment(14)
where do i see the file is genereated Error.svclog ?Attired
i have implemented in the web.config on my dev box but i dont see that it generate any svclog file is there any other setting needs to be taken care?Attired
The file will be generated in the same directory as your assembly. Most likely your bin directory. You may need recycle the worker process if you services are hosted in IIS.Proserpina
my wcf servcies is hosted on IIS on the dev box and i am using those servcies from my local machine, so i do have access to the folder/files are in dev box and i looked into bin folder and other foloers but could not find the log file...Attired
Make sure that your Application Pool - Identity has permission to write to that folder. I usually have a dedicated account assigned to my application pool, this way i can grant read\write access to that specific userProserpina
Will this Tracing will work in Release Mode. ? If yes.. how can we disable it ?Chromatogram
In the development environment, the Error file (initializeData="Error.svclog") is stored inside the solution project. Changing it to other locations did not work.Roadside
I recomand you to use the powerfull "Microsoft Service Configuration Editor" (embeded with visual studio in my case). You cannot do everything, but it helps a lot in understanding WCF configuration, including log configurationAvelinaaveline
I was able to get it to log to a folder by using this: initializeData="C:\wcflogs\wcf_svclog.svclog" />Malisamalison
@RohanWest - Actually - in my case the file was generated in the ROOT folder of my application (hosted on IIS), not the bin folder. It seems that it is relative to the web.config path, not the assembly path.Christiniachristis
What is myUserTraceSource?Burtburta
see how to configure it using a UI: https://mcmap.net/q/144021/-how-to-turn-on-wcf-tracing :-)Dewar
When i add the <system.diagnostics> tag under <configuration> i get an error saying The content type text/html of the response message does not match the content type of the binding (application/soap+xml;Climate
@user1152145, the solution to that problem is to paste it at the end of the file, just above </configuration>.Subminiature
H
37

In your web.config (on the server) add

<system.diagnostics>
 <sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
   <listeners>
    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\logs\Traces.svclog"/>
   </listeners>
  </source>
 </sources>
</system.diagnostics>
Hibbitts answered 24/11, 2010 at 21:3 Comment(2)
i have added like this since i dont have access to the dev except the folder initializeData="\\servername\drive$\Project\WCFTraces.svclog"/> and i dont see that file is generated after i try to access the services.Attired
By default it is buffered (may be able to change this). You can force it to flush by recycling the app pool. Also make sure the app pool identity can write to the location.Hibbitts
D
21

Go to your Microsoft SDKs directory. A path like this:

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools

Open the WCF Configuration Editor (Microsoft Service Configuration Editor) from that directory:

SvcConfigEditor.exe

(another option to open this tool is by navigating in Visual Studio 2017 to "Tools" > "WCF Service Configuration Editor")

wcf configuration editor

Open your .config file or create a new one using the editor and navigate to Diagnostics.

There you can click the "Enable MessageLogging".

enable messagelogging

More info: https://msdn.microsoft.com/en-us/library/ms732009(v=vs.110).aspx

With the trace viewer from the same directory you can open the trace log files:

SvcTraceViewer.exe

You can also enable tracing using WMI. More info: https://msdn.microsoft.com/en-us/library/ms730064(v=vs.110).aspx

Dewar answered 15/12, 2015 at 7:51 Comment(2)
thanks you so much for introducing me to this GUI utility. it will make editing the config files a lot easier!Hardening
Awesome.it helps me a lot to understand the Tracelog .Burgener
D
1

Instead of you manual adding the tracing enabling bit into web.config you can also try using the WCF configuration editor which comes with VS SDK to enable tracing

https://mcmap.net/q/145550/-trace-wcf-call-from-client

Downstate answered 7/7, 2014 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.