Thursday, 20 March 2014

Enable tracing in wcf

It’s very tough in WCF to identify the defect in the code, but with use of tracing we find out the dig down which method and which code is causing the issue in WCF service application.
IN WCF service Tracing is based on classes that resides in System.Diagnostic namespace. Important classes are TraceSource ,Trace and TraceListener.
Following steps to make tracing enable for WCF service;
1.    Configure WCF to release tracing information/Define Trace Source, we have the following options:
  • System.ServiceModel 
  • System.ServiceModel.MessageLogging 
  • System.ServiceModel.IdentityModel
  • System.ServiceModel.Activation 
  • System.Runtime.Serialization 
  • System.IO.Log
      In configuration file, we will define a source to enable this configuration as follows:
  <source name="System.ServiceModel.MessageLogging">
2.     Setting of Tracing Level, we have below options, we have to set this tracing level from below options other than default "Off":
·         Off
·         Critical
·         Error
·         Warning
·         Information
·         Verbose
·         ActivityTracing
·         All
      In configuration file, we can choose above values for switchValue attribute as follows:
  <source name="System.ServiceModel.MessageLogging"
                           switchValue="Information">
Configure Trace Listener
  <listeners>
    <add name="messages"
    type="System.Diagnostics.XmlWriterTraceListener"
    initializeData="d:\logs\messages.svclog" />
  </listeners>

No comments:

Post a Comment

Others

You will like to read it