Thursday, September 17, 2009

Enable WCF debugging trace and message logs

WCF debugging trace and message logs are sometimes very crucial in resolving WCF related issues. To enable the trace and message logs, the application configuration would be modified as following,
  1. within [system.serviceModel] and [/system.serviceModel] tags, add [diagnostics] [messageLogging maxMessagesToLog="30000"
    logEntireMessage="true"
    logMessagesAtServiceLevel="true"
    logMalformedMessages="true"
    logMessagesAtTransportLevel="true"]
    [/messageLogging]
    [/diagnostics]
  2. within [configuration] and [/configuration] tags, add [system.diagnostics]
    [sources]
    [source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" propagateActivity="true" ]
    [listeners]
    [add name="xml" /]
    [/listeners]
    [/source]
    [source name="System.ServiceModel.MessageLogging" switchValue="Verbose"]
    [listeners]
    [add name="xml" /]
    [/listeners]
    [/source]
    [/sources]
    [sharedListeners]
    [add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="WCFTracing.svclog" /]
    [/sharedListeners]
    [trace autoflush="true" /]
    [/system.diagnostics]
After modifying the configuration file, make sure the process hosting the WCF proxy or service has the write permission to the folder where the trace and message log file will reside.

After the trace and message log file is generated, the Service Trace Viewer could be used to analyze the trace and log file.

Here is a tutorial on how to use the Service Trace Viewer.

0 comments:

Post a Comment