Wednesday, July 18, 2012

WCF Service Traces using SVC Trace Viewer

In WCF projects, one would invariably need some kind of mechanism to ascertain whether the data is sent/received over the communication channel. One can definitely use fiddler for monitoring the data traffic over an http channel. But, WCF tracing provides a nifty way of verifying whether the data has been received/sent from WCF side.

It is easy to add the Tracing information in the WCF project. One would just need to add the diagnostics element in the web.config / app.config file of the WCF hosting project.
A sample element structure is shown below.

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information" propagateActivity="true">
        <listeners>
          <add name="corr"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="corr"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="corr" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\personal\Service.svclog">
      </add>
    </sharedListeners>
  </system.diagnostics>

"c:\personal\Service.svclog" is the absolute file path for the log file that will be generated from the WCF traces.
Navigate to the file location and view the log file in the SVC Trace Viewer for easy debugging.

No comments:

Post a Comment