Tuesday 10 July 2012

WCF TraceListener


WCF exception messages are very generic and tough to decode.

WCF default TraceListener Objects for core WCF Objects. I have mentioned below details description for some important objects.

Assembly Name
Description
System.ServiceModel
Logs the following
Message Process
Reading of Configuaration information
Transport-level action
Security request.
System.Runtime.Serialization
Emits the information when objects are serialized or deserialized. WCF always serializes and de- serializes information during the request so it is good event to see the content of the request.
System.ServiceModel.IdentityModel
Generates trace data for authentication and authorization.


The tracing information of these objects help you to find out any exception details easily.

You can enable tracing by adding below code in web.config file.

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="wcfTraceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="D:\logs\WcfTrace.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

After adding the above code in web.config file, WCF trace file will be created in the given location when you run WCFservice.

To view the file you need SvcTraceViewer.exe, which will be present in “C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin folder.” Or else you can referrer to the below link to get tool.