This project is read-only.

How to enable WCF message logging

- J.D. Meier, Carlos Farre, Jason Taylor, Prashant Bansode, Steve Gregersen, Madhu Sundararajan, Rob Boucher

You can enable message logging to log the messages processed by your service. Message logging can be used to diagnose your applications and analyze the root cause of problems. Message logging is not turned on by default. Turn on message logging by setting attributes on the <messagelogging> element in your configuration file and add a trace listener to log the events to a file.

Use the following steps to enable WCF message logging:
  1. Open the web.config file of the WCF service using the Configuration editor tool (SvcConfigEditor.exe).
  2. In the Configuration editor, navigate to the Diagnostics node, and click the Enable Message Logging link.
  3. This enables the message logging for your service and it also creates a listener (ServiceModelMessageLoggingListener) and a source (System.ServiceModel.MessageLogging) under the Listeners and Sources folder respectively.

You can configure Message logging levels at both the service and the transport levels. To configure the message logging levels,
  1. In the left pane, select MessageLogging under the Diagnostics node.
  2. Set the LogMessagesAtServiceLevel attribute to True choosing from the drop down. The LogMessagesAtTransportLevel attribute is True by default.

To determine where the messages will be logged select ServiceModelMessageLoggingListener under the Listeners node and note the value of the InitData attribute. The default location where messages are logged is c:\inetpub\wwwroot\WCFService\web_messages.svclog.

The configuration file should look as follows:
    <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>
        </sources>
        <sharedListeners>
            <add *initializeData="c:\inetpub\wwwroot\auditingwcf\web_messages.svclog"*
                type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                <filter type="" />
            </add>
        </sharedListeners>
    </system.diagnostics>


 <system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" *logMessagesAtServiceLevel="true"*
        logMessagesAtTransportLevel="true" />
    </diagnostics>

Additional Resources

Last edited Jun 13, 2008 at 6:28 PM by prashantbansode, version 1

Comments

No comments yet.