locked
Enabling WCF tracing RRS feed

  • Question

  • Hi , can someone provide me with some snippets to setup and  enable WCF tracing programatically ??? 

    thx ... steve
    Wednesday, October 28, 2009 4:37 PM

Answers

  • Hi,
    here is a configration for WCF tracing.
    configuration>
    <system.diagnostics>
      <sources>
        <source name="System.ServiceModel"
                switchValue="Information, ActivityTracing"
                propagateActivity="true" >
          <listeners>
            <add name="xml"/>
          </listeners>
        </source>
        <source name="System.ServiceModel.MessageLogging">
          <listeners>
            <add name="xml"/>
          </listeners>
        </source>
        <source name="myUserTraceSource"
                switchValue="Information, ActivityTracing">
          <listeners>
            <add name="xml"/>
          </listeners>
        </source>
      </sources>
      <sharedListeners>
        <add name="xml"
             type="System.Diagnostics.XmlWriterTraceListener"
                   initializeData="C:\logs\Traces.svclog" />
      </sharedListeners>
    </system.diagnostics>

    <system.serviceModel>
      <diagnostics wmiProviderEnabled="true">
          <messageLogging
               logEntireMessage="true"
               logMalformedMessages="true"
               logMessagesAtServiceLevel="true"
               logMessagesAtTransportLevel="true"
               maxMessagesToLog="3000"
           />
      </diagnostics>
    </system.serviceModel>
    </configuration>

    hope it can help you on the issue
    Frank Xu Lei--谦卑若愚,好学若饥
    专注于.NET平台下分布式应用系统开发和企业应用系统集成
    Focus on Distributed Applications Development and EAI based on .NET
    欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
    欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
    欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum
    Thursday, October 29, 2009 4:51 AM
  • add a App.config file to your console application and have this code

    <

     

    system.diagnostics>

    <

     

    sources>

    <

     

    source name="System.ServiceModel" switchValue="Warning, ActivityTracing"

     

     

    propagateActivity="true">

    <

     

    listeners>

    <

     

    add type="System.Diagnostics.DefaultTraceListener" name="Default">

    <

     

    filter type="" />

    </

     

    add>

    <

     

    add name="ServiceModelTraceListener">

    <

     

    filter type="" />

    </

     

    add>

    </

     

    listeners>

    </

     

    source>

    <

     

    source name="System.ServiceModel.MessageLogging">

    <

     

    listeners>

    <

     

    add name="messages"

     

     

    type="System.Diagnostics.XmlWriterTraceListener"

     

     

    initializeData="messages.svclog" />

    </

     

    listeners>

    </

     

    source>

    </

     

    sources>

    <

     

    sharedListeners>

    <

     

    add initializeData="app_tracelog.svclog"

     

     

    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

     

     

    name="ServiceModelTraceListener" traceOutputOptions="Timestamp">

    <

     

    filter type="" />

    </

     

    add>

    </

     

    sharedListeners>

    </

     

    system.diagnostics>

    <

     

    system.serviceModel>

    <

     

    diagnostics>

    <

     

    messageLogging logEntireMessage="true"

     

     

    logMalformedMessages="true"

     

     

    logMessagesAtServiceLevel="true"

     

     

    logMessagesAtTransportLevel="true"

     

     

    maxMessagesToLog ="1000"

     

     

    maxSizeOfMessageToLog="524288"/>

    </

     

    diagnostics>


    Rohan Fernando
    Thursday, October 29, 2009 9:00 AM

All replies

  • Hi,

    You cant do it programatically. You can have a look at the following link

    http://social.msdn.microsoft.com/forums/en-US/wcf/thread/25b17fef-5660-499d-ad1b-aaa3b8ab7f60/
    http://thoughtorientedarchitecture.blogspot.com/
    • Proposed as answer by Haripraghash Thursday, October 29, 2009 3:57 PM
    Wednesday, October 28, 2009 4:52 PM
  • Hi,
    here is a configration for WCF tracing.
    configuration>
    <system.diagnostics>
      <sources>
        <source name="System.ServiceModel"
                switchValue="Information, ActivityTracing"
                propagateActivity="true" >
          <listeners>
            <add name="xml"/>
          </listeners>
        </source>
        <source name="System.ServiceModel.MessageLogging">
          <listeners>
            <add name="xml"/>
          </listeners>
        </source>
        <source name="myUserTraceSource"
                switchValue="Information, ActivityTracing">
          <listeners>
            <add name="xml"/>
          </listeners>
        </source>
      </sources>
      <sharedListeners>
        <add name="xml"
             type="System.Diagnostics.XmlWriterTraceListener"
                   initializeData="C:\logs\Traces.svclog" />
      </sharedListeners>
    </system.diagnostics>

    <system.serviceModel>
      <diagnostics wmiProviderEnabled="true">
          <messageLogging
               logEntireMessage="true"
               logMalformedMessages="true"
               logMessagesAtServiceLevel="true"
               logMessagesAtTransportLevel="true"
               maxMessagesToLog="3000"
           />
      </diagnostics>
    </system.serviceModel>
    </configuration>

    hope it can help you on the issue
    Frank Xu Lei--谦卑若愚,好学若饥
    专注于.NET平台下分布式应用系统开发和企业应用系统集成
    Focus on Distributed Applications Development and EAI based on .NET
    欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
    欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
    欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum
    Thursday, October 29, 2009 4:51 AM
  • Are you sure about this ?? I run a self-hosted WCf service (as a console app), so there are no config files, only code. I've figured out how to setup the trace listeners, its only a question of activating the appropriate switchvalues and setting the trace source. Are you really sure, ie no config files, no tracing ???
    Thursday, October 29, 2009 8:08 AM
  • add a App.config file to your console application and have this code

    <

     

    system.diagnostics>

    <

     

    sources>

    <

     

    source name="System.ServiceModel" switchValue="Warning, ActivityTracing"

     

     

    propagateActivity="true">

    <

     

    listeners>

    <

     

    add type="System.Diagnostics.DefaultTraceListener" name="Default">

    <

     

    filter type="" />

    </

     

    add>

    <

     

    add name="ServiceModelTraceListener">

    <

     

    filter type="" />

    </

     

    add>

    </

     

    listeners>

    </

     

    source>

    <

     

    source name="System.ServiceModel.MessageLogging">

    <

     

    listeners>

    <

     

    add name="messages"

     

     

    type="System.Diagnostics.XmlWriterTraceListener"

     

     

    initializeData="messages.svclog" />

    </

     

    listeners>

    </

     

    source>

    </

     

    sources>

    <

     

    sharedListeners>

    <

     

    add initializeData="app_tracelog.svclog"

     

     

    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

     

     

    name="ServiceModelTraceListener" traceOutputOptions="Timestamp">

    <

     

    filter type="" />

    </

     

    add>

    </

     

    sharedListeners>

    </

     

    system.diagnostics>

    <

     

    system.serviceModel>

    <

     

    diagnostics>

    <

     

    messageLogging logEntireMessage="true"

     

     

    logMalformedMessages="true"

     

     

    logMessagesAtServiceLevel="true"

     

     

    logMessagesAtTransportLevel="true"

     

     

    maxMessagesToLog ="1000"

     

     

    maxSizeOfMessageToLog="524288"/>

    </

     

    diagnostics>


    Rohan Fernando
    Thursday, October 29, 2009 9:00 AM
  • Hi ... works ... thx very much ...
    Thursday, October 29, 2009 2:54 PM
  • Welcome~
    Frank Xu Lei--谦卑若愚,好学若饥
    专注于.NET平台下分布式应用系统开发和企业应用系统集成
    Focus on Distributed Applications Development and EAI based on .NET
    欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
    欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
    欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum
    Thursday, October 29, 2009 4:09 PM
  • Add these tags in the config section of the service.

    <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>

     

    I think this should help

    Regards

    Rac


    Suggestions Appreciated
    • Proposed as answer by Rac19 Thursday, March 10, 2011 12:14 PM
    Wednesday, March 9, 2011 7:08 AM