Search This Blog

Tuesday, August 23, 2011

How to enable WCF Tracing?

Tracing is not enabled by default. Trace source should be defined in the assembly level. The System.ServiceModel and System.ServiceModel.MessageLogging are the most important and frequently used WCF trace sources.

For each trace source trace listener should be defined. You can configure tracing by editing the web.config for web-hosted applications, or Appname.exe.config for self-hosted applications.


<configuration>

  <system.diagnostics>
   <sources>
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
    <listeners>
   <add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
    </listeners>
   </source>
  </sources>
</system.diagnostics>
</configuration>

You can also configure each trace source to use the same shared listener, as shown below.


<configuration>

  <system.diagnostics>
   <sources>
    <source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
     <listeners>
      <add name="xml" />
       </listeners>
        </source>
         <source name="CardSpace">
       <listeners>
     <add name="xml" />
   </listeners>
</source>
<source name="System.IO.Log">
<listeners>
   <add name="xml" />
     </listeners>
      </source>
       <source name="System.Runtime.Serialization">
     <listeners>
    <add name="xml" />
</listeners>
   </source>
      <source name="System.IdentityModel">
       <listeners>
          <add name="xml" />
       </listeners>
   </source>
</sources>

<sharedListeners>

<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\log\Traces.svclog" />
</sharedListeners>
</system.diagnostics>
</configuration>

No comments:

Post a Comment