Tips for working with WCF traces

Posted on November 10, 2010 by

0


Activating WCF traces

Enabling WCF traces is done by adding the following section to the application app.config and restarting the application:

<configuration>
     <system.diagnostics>
       <sources>
         <source name="System.ServiceModel"
                 switchValue="Information, ActivityTracing"
                 propagateActivity="true">
           <listeners>
             <add name="traceListener"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData= "c:\logs\client1.svclog" />
             </listeners>
         </source>
       </sources>
       <trace autoflush="true" />
    </system.diagnostics>
</configuration>

A few things to notice:

The directory in the “initializeData” path should exist, and you should have write permissions to it

Add the “autoflash” flag with true to log writing the traces after each operation

The SwtichValue controls the traces level, according to the following table:

Trace Level Description
Off Ignore all trace messages
Critical Log unexpected processing events or unhandled exceptions have occurred. The application will terminate immediately or shortly.
Error An unexpected processing event or exception has occurred. The application is still capable of continuing its processing.
Warning Indicates there is a possible problem but the application will continue running.
Information Application is running smoothly only that informative message is recorded. In this case messages are just milestones.
Verbose Very similar to information but provides more details as compared.
ActivityTracing In this case messages are related to communication between components and the activities.
All In this case all messages are captured.

Analyzing the WCF traces

The trace file should be opened with SvcTraceViewer.exe (located in C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin)

When you have both the client and the server traces, to better understand the flow, open one of the trace files, and drag the second one into the opened window.

clip_image002

This will cause both the client and the server trace files to be opened in the same window.

clip_image004

Now, go to the Graph tab in the left part of the window. It will show all the flow sequence between the client and the server in a sequence graph, and will mark the places in which exceptions were thrown. When pressing a line in the graphon the left part, SvcTraceViewer will mark the corresponding line in the description window (on the right), which gives additional information on what happened in the flow (including the exception stack), in the selected timestamp.

clip_image006

Advertisements
Posted in: WCF traces