Tips for working with WCF traces

Posted on November 10, 2010 by


Activating WCF traces

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

         <source name="System.ServiceModel"
                 switchValue="Information, ActivityTracing"
             <add name="traceListener"
                 initializeData= "c:\logs\client1.svclog" />
       <trace autoflush="true" />

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.


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


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.


Posted in: WCF traces