Using of WCF Trace

Damir Dobric Posts

Next talks:

 

Damir@Phone    

Follow me on Twitter: #ddobric



 

 

Archives

Tracing in WCF is could be very powerful feature helping to diagnostic activities behind the scene. Unfortunately it is not well documented and not often used at all. In this post I will describe how to use WCF tracing.

Trace in WCF is is build on top of .NET Trace features. It means internally WCF use TraceSource-s. The WCF trace source behind the scene is implemented in the class System.Diagnostics.XmlWriterTraceListener in System assembly. That means it does not have anything to do with WCF. If this is true, then it should be possible to use Microsoft Service Trace Viewer tool without WCF too.

Additionally, it is important to know that WCF use two different sources System.ServiceModel and  System.ServiceModelMessageLogging. Both sources are based on XmlWriterListener. That means that even the format of messages in both sources is the same. First one is used for tracing purposes and second one for tracking of messages.

I use usually second one for tracking. If some bad error occurs I usually switch to the first one. Here is the configuration for both. Note that switchValue "Information" is highlighted and no propagateActivity attribute is set (if used this attribute could cause some issues. If you use Service Config Editor this attribute is by default set on true).

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging"
           switchValue="Information, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="c:\\temp\\Web_tracelog.svclog"
       type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0,
             Culture=neutral, PublicKeyToken=b77a5c561934e089
"

       name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
      <add initializeData="c:\\temp\\Web_messages.svclog"
       type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0,
             Culture=neutral, PublicKeyToken=b77a5c561934e089
"
       name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

If you want to use a trace you do not need any service. Just execute this code below and open c:\\temp\\Web_tracelog.svclog. with WCF Trace Viewer. Picture below shows the result.

image


Posted Mar 24 2009, 11:08 PM by Damir Dobric
Filed under:

Comments

Vatroslav Mihalj wrote re: Using of WCF Trace
on 03-25-2009 9:33

Damir, have you ever thought of collecting your blog posts on WCF into a book :) ? It might fit well into Apress "...A Problem-Solution Approach" series

Damir Dobric wrote re: Using of WCF Trace
on 03-25-2009 10:53

Intersting question. Writing of book is not well payed job :). I was thinking on "Harry Potter about .NET".

Damir Dobric wrote re: Using of WCF Trace
on 05-15-2009 16:23

Continued: Source Code for result shown above: developers.de/.../code-which-write-to-wcf-trace.aspx

Damir Dobric wrote re: Using of WCF Trace
on 05-15-2009 17:45

Here is the source code of the short sample, which write messages in the trace file in two threads:developers.de/.../5371.aspx

Chris wrote re: Using of WCF Trace
on 12-09-2010 19:48

Nice description. Any idea why the file would balloon to 3 GIG? Not one program will open it now because the size if too big...

hsupowei wrote re: Using of WCF Trace
on 01-26-2011 8:34

great! thanks !

Damir Dobric Posts wrote Tuning IIS for large WCF Message
on 10-13-2011 17:53

Sometimes there are situations which require transfer of large messages when using web services. When

DamirDobric wrote Tuning IIS for large WCF Message
on 10-13-2011 18:22

Sometimes there are situations which require transfer of large messages when using web services. When

rifzagdfw wrote re: Using of WCF Trace
on 09-07-2012 18:07

DyBK9T  <a href="qaffusoavtvf.com/.../a>, [url=http://jmxiuogynury.com/]jmxiuogynury[/url], [link=http://ovajlwbybslf.com/]ovajlwbybslf[/link], http://yhmforoboblf.com/

developers.de is a .Net Community Blog powered by daenet GmbH.