Monday, August 20, 2012

WCF - Windows Communication Foundation - Message Logging

Add the below lines in WCF web.config file : 
<system.diagnostics>
  <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
                 <add name="messagesListner"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\logfolder\messages.svclog" />
          </listeners>
      </source>
    </sources>
</system.diagnostics>

<system.serviceModel>
  <diagnostics>
    <messageLogging 
         logEntireMessage="true" 
         logMalformedMessages="false"
         logMessagesAtServiceLevel="true" 
         logMessagesAtTransportLevel="false"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
</system.serviceModel> 
 
 
In WCF two types of source available
1. System.ServiceModel.MessageLogging
2. System.ServiceModel
 
In this post i used xmlwriter of tracing, you can use other types of listners also.
 
*Note : Use svcConfigEditor to edit the wcf config file.