Just Code‎ > ‎

WCF - Trace and log all incomming SOAP messages with Envelope and all

posted Feb 12, 2013, 1:46 AM by Peter Henell   [ updated Feb 12, 2013, 1:47 AM ]
Add this configuration to enable trace and logging of all incomming SOAP messages to your WCF services. The two sources will log different things, so make sure to add them both to get all the available information.

Double click on the resulting .svclog-files to open them in the Microsoft Service Trace application.
<system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
          propagateActivity="true">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>

    <sharedListeners>
      <add initializeData="C:\log\service_Messages.svclog"
          type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
      <add initializeData="C:\log\service.svclog"
          type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />

    <switches>
      <add name="TraceLevelSwitch" value="4" />
      <add name="DataMessagesSwitch" value="1" />
    </switches>
  </system.diagnostics>
 <system.serviceModel>

    <diagnostics>
      <messageLogging
           logEntireMessage="true"
           logMalformedMessages="true"
           logMessagesAtServiceLevel="true"
           logMessagesAtTransportLevel="true"
           maxMessagesToLog="25"
           maxSizeOfMessageToLog="20000000"/>
    </diagnostics>
...
</system.serviceModel>
Comments