Configure WCF logging

To configure WCF logging you can use the standard tools provided by Microsoft. This posting describes how to configure your client to log the messages it sends to a service.

The original app.config looks like this. There is one endpoint listening on localhost:1122/Registration.svc

<?xml version="1.0" encoding="utf-8"?>   
<configuration>      
    <system.serviceModel>      
        <bindings>      
            <customBinding>      
                <binding name="CustomBinding_IRegistration">      
    
                    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"      
                        messageVersion="Soap11WSAddressing10" writeEncoding="utf-8">    
                        <readerQuotas     
                            maxDepth="32"     
                            maxStringContentLength="8192"     
                            maxArrayLength="16384"    
                            maxBytesPerRead="4096"     
                            maxNameTableCharCount="16384" />    
                    </textMessageEncoding>    
   
                    <httpTransport     
                        manualAddressing="false"     
                        maxBufferPoolSize="524288"    
                        maxReceivedMessageSize="65536"     
                        allowCookies="false"     
                        authenticationScheme="Anonymous"    
                        bypassProxyOnLocal="false"     
                        hostNameComparisonMode="StrongWildcard"    
                        keepAliveEnabled="true"     
                        maxBufferSize="65536"     
                        proxyAuthenticationScheme="Anonymous"    
                        realm=""     
                        transferMode="Buffered"     
                        unsafeConnectionNtlmAuthentication="false"    
                        useDefaultWebProxy="true" />    
                </binding>    
            </customBinding>    
        </bindings>    
        <client>    
            <endpoint     
                address="http://localhost:1122/Registration.svc"     
                binding="customBinding"    
                bindingConfiguration="CustomBinding_IRegistration"     
                contract="IRegistration"    
                name="CustomBinding_IRegistration">    
                <identity>    
                    <dns value="localhost" />    
                </identity>    
            </endpoint>    
        </client>    
    </system.serviceModel>    
</configuration

Navigate to the folder “c:Program FilesMicrosoft SDKsWindowsv6.0Abin” and start SvcConfigEditor.exe. Open the app.config (Ctrl+O) of the application which you want to monitor. In this example I use the app.config as shown above.

Select the Diagnostic branch of the tree view on the left. Click on the link “Enable MessageLogging” on the left. After clicking this link an entry is added to the “Listeners” section and the “Sources” section.

What has happened to your app.config?

A section “system.diagnostics” has been added below your “configuration” section:

<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:logapp_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>

Below your “system.serviceModel” (in the “configuration” section) a “diagnostics” section is added:

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

Select the “Message Logging” entry below the “Diagnostics” entry in the tree view on the left. Set the value for “LogEntireMessage” to true (default is false). This stores the complete message in the log (otherwise only the header of the message is stored).

Go to the “Listeners” entry in the tree view and select the first entry below it (ServiceModelMessageLoggingListener). The location for your logfile is specified in the “InitData” attribute of the listener. Change this to e.g. “c:logapp_messages.log”.

Run the client for your WCF service and execute several requests to the service. The file “app_message.svclog” in the directory “c:log” should now exist and contain message information.

The created .svclog file is a plain XML text file. You can parse this file with the SvcTraceViewer.exe. Double click the “app_message.svclog” in the “c:log” folder. The SvcTraceViewer starts; select the Message tab.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *