Tracing in WCF: Understanding basic steps

Theory behind WCF Tracing is not an exception of classical definition of Tracing. Through Tracing an application provides information about itself. Information may vary from internal state of object to passed input parameter to method. This information should be logged, persisted or saved somewhere.

WCF Tracing can be used for the instrumentation of the WCF Service.

There are essentially four steps involved in WCF Tracing


Emitting Trace information from Service

To emit trace information WCF provides different sources. However you have choice to create trace source using TraceSource class as well. You can choose any of WCF Assembly level trace source to emit the tracing information.

WCF Assembly level Trace Sources are as below,

  1. System.ServiceModel
  2. System.ServiceModel.MessageLogging
  3. System.ServiceModel.IdentityModel
  4. System.ServiceModel.Activation
  5. System.Runtime.Serilization
  6. System.IO.Log

Setting the Trace level

You can define the level of messages you want to trace. If you are tracing all level of messages then size of message generated for tracing would be very bulky and it may affect application negatively.

WCF supports below tracing levels


Trace level information is set by using the switchValue attribute for trace source.

Configuring the listener

You need to configure a listener to persist the messages at any desired location. There must be at least one listener configured for WCF tracing.

Listener can be configured either

  1. Through code
  2. Or in configuration file.

You can configure listener directly in source element of the configuration.

Note: In further post, I will discuss in detail on configuring the listener.

Enabling Message logging

Last step you need to perform is to enable message logging in configuration. WCF logs message at two levels.


Different attributes of Message loggings are as below,


Enough of theory Smile Now let us go ahead and capture basic trace in WCF service.

  1. Create a basic WCF Service
  2. Consume service in a client. I am assuming that you are consuming service in a console client.
  3. Open App.config of console client

Emit Trace Information

Add a source in System.Diagostics


Set the Trace Level


We are setting here trace level to Information and Activity tracing

Configure the Listener


We are using listener System.Diagnostics.XmlWriterTraceListener. Trace information would be find at Traces.svclog file under bin/debug folder .

Trace information gets buffered, so to make it visible you need to flush it using below configuration


After performing above three steps your System.Diagnostics should look like below,


Enable Message Logging

Last step you need to perform is enabling Message logging. Add below diagnostic in System.ServiceModel.


Eventually client side App.Config should look more or less like below, Smile

<?xml version="1.0" encoding="utf-8" ?>
        <messageLogging logEntireMessage="true"
                <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
            <endpoint address="http://localhost:2934/Service1.svc" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
                    <dns value="localhost" />
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Information, ActivityTracing">
          <add name="log"
    <trace autoflush ="true"/>

After configuring as said above when you run client application you will get a file in


Open above file to view the trace Smile I hope this post was useful. In further post I will take you to dipper in tracing. Thanks for reading Smile


Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

3 responses to “Tracing in WCF: Understanding basic steps”

  1. Nice one short overview to beginer level….:)


  2. very nice articles… keep sharing your information.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at