Wednesday, February 22, 2012

WCF Tracing–Message Logging and Tracing

Note: this is an update to my previous post: http://blog.aggregatedintelligence.com/2011/09/wcfsetting-up-tracing.html

Tracing is a useful way to determine problems with WCF. You can enable them through your config file.

Here is how you can enable both message logging (which logs the messages being sent to the WCF service) and tracing (which allows you to see all the steps through which WCF is going in servicing your request):

Under <configuration> add System.Diagnostics as shown below:

<system.diagnostics>
  <sources>
   
    <!—tracing is enabled through this section—>

    <source propagateActivity="true" name="System.ServiceModel"
    switchValue="Information, ActivityTracing">
      <listeners>
        <add type="System.Diagnostics.DefaultTraceListener"
        name="Default">
          <filter type="" />
        </add>
        <add name="sdt">
          <filter type="" />
        </add>
      </listeners>
    </source>

    <!—message logging is enabled through this section—>
    <source name="System.ServiceModel.MessageLogging"
    switchValue="Information, ActivityTracing">
      <listeners>
        <add type="System.Diagnostics.DefaultTraceListener"
        name="Default">
          <filter type="" />
        </add>
        <add name="ServiceModelMessageLoggingListener">
          <filter type="" />
        </add>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add initializeData="web_messages.svclog"
    type="System.Diagnostics.XmlWriterTraceListener"
    name="ServiceModelMessageLoggingListener"
    traceOutputOptions="Timestamp">
      <filter type="" />
    </add>
    <add initializeData="traceLog.svclog"
    type="System.Diagnostics.XmlWriterTraceListener" name="sdt"
    traceOutputOptions="DateTime, Timestamp">
      <filter type="" />
    </add>
  </sharedListeners>
  <trace autoflush="true" />
</system.diagnostics>

Under <system.serviceModel> add the diagnostics node as shown below:


<diagnostics>
  <messageLogging logEntireMessage="true"
  logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>

No comments: