Freigeben über


Tip: Peer Channel diagnostics using WCF Tracing/Message Logging

Scenario: You want to enable WCF tracing for troubleshooting purposes

Tip: You need to use the App.config file to enable WCF Tracing and Message Logging. The following (either 1 or 2 depending on your scenario) will end up generating a .svclog file named MyAppTraceFile.svclog. This file is viewable using the ServiceTraceViewer.exe tool (shipped with the Windows SDK - maybe found in the Tools directory)

1. If you already have an App.config file that your application uses, modify it as follows:

a. In the <system.serviceModel> section in your file, add the following tag:

<diagnostics wmiProviderEnabled="true">

            <messageLogging maxMessagesToLog="30000"

                    logEntireMessage="true"

                    logMessagesAtServiceLevel="true"

                    logMalformedMessages="true"

                    logMessagesAtTransportLevel="true">

            </messageLogging>

</diagnostics>

b. Now, add the following additional <system.diagnostics> section anywhere after your <system.serviceModel> ends but within the root <configuration> section.

<system.diagnostics>

        <sources>

            <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >

                <listeners>

                    <add name="xml" />

                </listeners>

            </source>

            <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">

                <listeners>

                    <add name="xml" />

                </listeners>

            </source>

        </sources>

        <sharedListeners>

            <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="MyAppTraceFile.svclog" />

        </sharedListeners>

        <trace autoflush="true" />

    </system.diagnostics>

 

2. If you have configured PeerChannel imperatively in code and don’t have a config file that your App uses, simply create one with the following contents:

<configuration>

    <system.serviceModel>

        <diagnostics wmiProviderEnabled="true">

            <messageLogging maxMessagesToLog="30000"

                    logEntireMessage="true"

                    logMessagesAtServiceLevel="true"

                    logMalformedMessages="true"

                    logMessagesAtTransportLevel="true">

            </messageLogging>

        </diagnostics>

    </system.serviceModel>

    <system.diagnostics>

        <sources>

            <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >

                <listeners>

                    <add name="xml" />

                </listeners>

            </source>

            <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">

                <listeners>

                    <add name="xml" />

                </listeners>

            </source>

        </sources>

        <sharedListeners>

            <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="MyAppTraceFile.svclog" />

        </sharedListeners>

        <trace autoflush="true" />

    </system.diagnostics>

</configuration>

 

-Shalini.

Comments