Thursday, May 31, 2012

How to Turn on WCF Tracing in 2 steps


There are two steps to turn on WCF tracing.
First is to add a source as shown below inside 'Configuration' element

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add
          name="messages"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="Messages.svclog" />
        listeners>
      source>
    sources>
  system.diagnostics>
 

And second is to put the following inside the 'System.ServiceModel' element to start tracing.


<diagnostics>
      <messageLogging
      logEntireMessage="true"
      logMalformedMessages="true"
      logMessagesAtServiceLevel="true"
      logMessagesAtTransportLevel="false"
      maxMessagesToLog="0x7fffffff"
      maxSizeOfMessageToLog="0x7fffffff"/>
diagnostics>

After that your messages will be logged into a file called Messages.svclog.