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?

4 Answers 4

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.

14
  • 19
    where do i see the file is genereated Error.svclog ?
    – Nick Kahn
    Nov 24, 2010 at 21:16
  • 4
    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.
    – Rohan West
    Nov 24, 2010 at 21:22
  • 9
    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 user
    – Rohan West
    Nov 24, 2010 at 21:39
  • 2
    In the development environment, the Error file (initializeData="Error.svclog") is stored inside the solution project. Changing it to other locations did not work.
    – LCJ
    Sep 14, 2012 at 4:48
  • 6
    I was able to get it to log to a folder by using this: initializeData="C:\wcflogs\wcf_svclog.svclog" /> Aug 2, 2013 at 12:51
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>
2
  • 1
    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.
    – Nick Kahn
    Nov 24, 2010 at 21:12
  • 6
    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.
    – Christoph
    Jul 7, 2011 at 18:50
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

2
  • 2
    thanks you so much for introducing me to this GUI utility. it will make editing the config files a lot easier!
    – symbiont
    Sep 30, 2016 at 9:33
  • Awesome.it helps me a lot to understand the Tracelog .
    – ksrds
    Apr 20, 2020 at 14:04
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://stackoverflow.com/a/16715631/2218571

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.