Thursday, September 06, 2012

WCF Diagnostics

Have you seen weird error messages while using WCF Services and unable to figure out easily as what’s going on? Add the following diagnostics configuration in you config file under configuration section, may be at the bottom. It will generate a file named “App_tracelog.svclog”, you can open as XML file and read the info and may be able to trace the problem easily.

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener"/>
        </listeners>
      </source>
 
      <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener"/>
        </listeners>
      </source>
      <source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp"/>
    </sharedListeners>
  </system.diagnostics>

The file will be generated on the same level where config file is available. Make sure to either comment or remove this configuration once you resolved the issue else it may impact the performance and use unnecessary disk space.

No comments: