How to Enable Activity Tracing in WCF?

WCF provides functionality that enables you to monitor the activities that your services and client applications perform when they run. Tracing is not enabled by default. To activate tracing, you must create a trace listener and set a trace level other than Off for the selected trace source in your configuration

How to Enable Activity Tracing in WCF?

You can enable activity tracing either programmatically in a class file or declaratively in an application configuration file. If you choose to use the declarative approach, you can add your activity tracing configuration to the Diagnostics folder by using the WCF Configuration Editor. The WCF Configuration Editor does not require you to write raw XML.

Step 1

Add a source element for the System.ServiceModel trace source.

 

  <system.diagnostics>

    <sources>

      <source name="System.ServiceModel"

      </source>

    </sources>

  </system.diagnostics>

Step 2

Set the switchValue property to specify which activities are to be recorded. You can specify the activities individually or you can combine them in a comma-separated list.

  <system.diagnostics>

    <sources>

      <source name="System.ServiceModel"

              switchValue="Information, ActivityTracing"

              propagateActivity="true">

      </source>

    </sources>

  </system.diagnostics>

For more information about switchValue settings, see the references that are listed below the table

Step 3

Add a trace listener. Specify the type of listener and the complete file name where the trace activities are to be recorded.

  <system.diagnostics>

    <sources>

      <source name="System.ServiceModel"

              switchValue="Information, ActivityTracing"

              propagateActivity="true">

        <listeners>

          <add name="traceActivity"

               type="System.Diagnostics.XmlWriterTraceListener"

               initializeData= "c:\\logs\\activity.svclog" />

        </listeners>

      </source>

    </sources>

  </system.diagnostics>

Step 4

Set the autoflush property to true. This tells the trace listener to push the traces to the log after every write operation rather than buffering them in memory.

  <system.diagnostics>

    <trace autoflush="true" />

    <sources>

      <source name="System.ServiceModel"

              switchValue="Information, ActivityTracing"

              propagateActivity="true">

        <listeners>

          <add name="traceActivity"

               type="System.Diagnostics.XmlWriterTraceListener"

               initializeData= "c:\\logs\\activity.svclog" />