CTS – Your Technology Partner

WCF Tracing

Written by Craig Butler on December 3, 2012

by: Natasha Shakhmatov

First thing first. If you plan to work with WCF do yourself a favor and learn how to use the Service Trace Viewer Tool (SvcTraceViewer.exe).

http://msdn.microsoft.com/en-us/library/ms732023(v=vs.100).aspx

This is an easy to install, easy to use, easy to configure tool that has the potential of saving you countless hours of frustrating debugging.

Here are the steps:

1. SvsTraceViewer.exe can be found here C:\Program Files\Microsoft SDKs\Windows\vX.X\Bin

If you do not have the C:\Program Files\Microsoft SDKs folder it means that Windows SDK tools are not installed on the machine. You can get the SDK here:

http://msdn.microsoft.com/en-us/windows/bb980924.aspx

Note that you only need to install the Tools:

clip_image001

2. Configure tracing in the application’s config file. Below are the instructions copied from the MSDN site:

You can configure tracing using the application’s configuration file-either Web.config for Web-hosted applications, or Appname.config for self-hosted applications. The following is an example:

 1: <system.diagnostics>

 2:     <trace autoflush="true" />

 3:     <sources>

 4:             <source name="System.ServiceModel"

 5:                     switchValue="Information, ActivityTracing"

 6:                    propagateActivity="true">

 7:             <listeners>

 8:                <add name="sdt"

 9:                    type="System.Diagnostics.XmlWriterTraceListener"

 10:                    initializeData= "SdrConfigExample.e2e" />

 11:             </listeners>

 12:          </source>

 13:     </sources>

 14: </system.diagnostics>

In this example, the name and type of the trace listener is specified. The Listener is named sdt and the standard .NET Framework trace listener (System.Diagnostics.XmlWriterTraceListener) is added as the type. The initializeData attribute is used to set the name of the log file for that Listener to be SdrConfigExample.e2e. For the log file, you can substitute a fully-qualified path for a simple file name.

The example creates a file in the root directory called SdrConfigExample.e2e. When you use the Trace Viewer to open the file as described in the “Opening and Viewing WCF Trace Files” section, you can see all the messages that have been sent.

Note: you can just copy and paste the example above into your config file and it will work fine. I recommend, however changing the file name to have a .svclog extension. This way you can just double-click on the file to start the viewer.

Here is my config:

 1: <system.diagnostics>

 2:     <trace autoflush="true" />

 3:     <sources>

 4:       <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">

 5:         <listeners>

 6:           <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\ScIDMSUSPSserverlog.svclog" />

 7:         </listeners>

 8:       </source>

 9:     </sources>

 10:   </system.diagnostics>

This is what the trace looks like opened in the viewer.clip_image001[4]

Comments

comments