What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 27648 |  Welcome, Guest!   Register  Login
 Home > Blogs > WCF > Simple steps to enable tracing in WCF ...
Imghani

Simple steps to enable tracing in WCF

 Blog author: Imghani | Posted on: 7/17/2012 | Category: WCF Blogs | Views: 777 | Status: [Member] | Points: 75 | Alert Moderator   


Tracing mechanism in Windows Communication Foundation is based on the classes that resides in System.Diagnostic namespace.Important classes are Trace, TraceSource and TraceListener.

Following are the steps to enable tracing in WCF:
1. Configuring WCF to emit 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
  • Cardspace
      In configuration file, we will define a source to enable this configuration as follows:
     <source name="System.ServiceModel.MessageLogging">
2. Setting Tracing Level, we have the following available options, we need to set this tracing level to available 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">
3. Configuring a trace listener     For configuring a trace listener, we will add following to config file.
      <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="d:\logs\messages.svclog" />
      </listeners>
4. Enabling message logging
<system.serviceModel>
         <diagnostics>
            <messageLogging
                    logEntireMessage="true"
                    logMalformedMessages="false"
                    logMessagesAtServiceLevel="true"
                    logMessagesAtTransportLevel="false"
                    maxMessagesToLog="3000"
                    maxSizeOfMessageToLog="2000"/>
         </diagnostics>
    </system.serviceModel>
logEntireMessage: By default, only the message header is logged but if we set it to true, entire message including message header as well as body will be logged.
logMalformedMessages: this option log messages those are rejected by WCF stack at any stage are known as malformed messages.
logMessagesAtServiceLevel: messages those are about to enter or leave user code.
logMessagesAtTransportLevel: messages those are about to encode or decode.
maxMessagesToLog: maximum quota for messages. Default value is 10000.
maxSizeOfMessageToLog: message size in bytes.

Putting all this together, configuration file will appear like this.
<system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messagelistener"
               type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\logs
\myMessages.svclog"></add>         </listeners>       </source>     </sources>   </system.diagnostics>     <system.serviceModel>              <diagnostics>         <messageLogging logEntireMessage="true"                         logMessagesAtServiceLevel="false"                         logMessagesAtTransportLevel="false"                         logMalformedMessages="true"                         maxMessagesToLog="5000"                         maxSizeOfMessageToLog="2000">                  </messageLogging>       </diagnostics>     </system.serviceModel>
Note: In this case, information will be buffered and not published to file automatically, So, we can set the autoflush property of the trace under sources as follows:
<trace autoflush ="true" />





Imran Abdul Ghani
http://www.topwcftutorials.net
Found interesting? Add this to:



 More Blogs from Imghani

     More ...

    About Imran Ghani

    Experience:11 year(s)
    Home page:http://www.topwcftutorials.net
    Member since:Sunday, June 03, 2012
    Level:Starter
    Status: [Member]
    Biography:Working as Sr. Software Engineer in Emaratech, Dubai, UAE. You can reach his blogging at WCF Tutorials.
    >> Write Response - Respond to this post and get points

    More Blogs

    About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
    General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
    Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 4:35:59 PM