Saturday, August 1, 2015

Tracing in WCF Service

Tracing in wcf service enabled developers to get logged information about events. Only config settings can enable tracing in wcf.

Below given are trace levels, combination of these trace levels can be used  for 'SwitchValue' attribute of Source element.
  • Critical 
  • Error  
  • Warning 
  • Information
  • Verbose
  • Activity Tracing
  • All
There are number of Trace sources, traces generated within an assembly are accessed by the listeners defined for that source.
Common listener file can be used for different configured traces sources.
Commonly used is System.ServiceModel
  • System.ServiceModel: Logs all stages of WCF processing, whenever configuration is read, a     message is processed in transport, security processing, a message is dispatched in user code, and so on.
  • System.ServiceModel.MessageLogging: Logs all messages that flow through the system.
  • System.IdentityModel
  • System.ServiceModel.Activation
  • System.IO.Log: Logging for the .NET Framework interface to the Common Log File System (CLFS).
  • System.Runtime.Serialization: Logs when objects are read or written.

Config Settings:
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior >
          <serviceMetadata httpGetEnabled="true" />         
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <diagnostics>
      <messageLogging logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
        logMalformedMessages="true" maxMessagesToLog="20000" maxSizeOfMessageToLog="10000">       
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"  switchValue="Error, Critical" >
        <listeners >
          <add name="log" initializeData="E:\TracedLog.svclog" type="System.Diagnostics.XmlWriterTraceListener"></add>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>


Multiple Sources can be defined to listen on shared file
    <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>


No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...