Levels of Tracing, Part 3

Although often associated with event tracing, message logging is actually a separate facility from the standard levels of tracing. Message logging is not enabled by default just like event tracing is not enabled by default. You activate message logging by adding a trace source and listener to the configuration file as we saw last time. The first difference is that the trace source you need to add is System.ServiceModel.MessageLogging instead of the System.ServiceModel trace source that we were using for event tracing.

I've done the minimal changes to the previous example to show how message logging is enabled.

 <configuration>
 <system.diagnostics>
  <sources>
   <source name="System.ServiceModel.MessageLogging">
    <listeners>
     <add initializeData="c:\messagelog.svclog" 
          type="System.Diagnostics.XmlWriterTraceListener"
          name="messagelog">
     </add>
    </listeners>
   </source>
  </sources>
 </system.diagnostics>
</configuration>

The second difference is that the System.SerivceModel.MessageLogging trace source ignores all of those different trace levels that we talked about. If you provide a trace level to this trace source, then it has no effect. Instead, there is a separate configuration section specifically for message logging.

 <configuration>
 <system.serviceModel>
  <diagnostics>
   <messageLogging logEntireMessage="true" 
                   logMalformedMessages="false"
                   logMessagesAtServiceLevel="false" 
                   logMessagesAtTransportLevel="true"
                   maxMessagesToLog="100"
                   maxSizeOfMessageToLog="65536"/>
  </diagnostics>
 </system.serviceModel>
</configuration>

Next time I'll do a rundown of these options and some recommended settings for message logging.