Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF: How do I trace message bodies?

Tags:

logging

trace

wcf

I'm trying to diagnose a WCF service that is self-hosted in a relatively simple service host process (Service.exe).

I have Service.exe.config configured thus:

<?xml version="1.0" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" 
              switchValue="All"
              propagateActivity="true">
        <listeners>
          <add name="traceListener" 
               type="System.Diagnostics.XmlWriterTraceListener" 
               initializeData= "c:\temp\Service.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="1"
                      maxSizeOfMessageToLog="2147483647"
                      logEntireMessage="true"
                      logMessagesAtServiceLevel="true"
                      logMalformedMessages="true"
                      logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0"
                      sku=".NETFramework,Version=v4.0" />
  </startup>
</configuration>

When I look at the resulting svclog file, I see many trace events being logged (I expected only the first message to be logged), and none of the messages being traced show a message body (only headers).

I'm sure I must be missing something simple here, but I don't see it.

UPDATE: When I look at the WCF Config Editor, there are two sections under "Diagnostics": MessageLogging and Tracing. When I click the "EnableMessageLogging" link, my config file gets updated:

  <system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="All">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add initializeData="c:\temp\MessageBodyTracing.svclog" type="System.Diagnostics.XmlWriterTraceListener"
            name="traceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, 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:\users\me\documents\visual studio 2010\projects\messagebodytracing\messagebodytracing\app_messages.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>

I guess the source named System.ServiceModel.MessageLogging is the key - I hadn't seen that in any documentation of message tracing...

like image 744
lesscode Avatar asked Jun 29 '12 15:06

lesscode


People also ask

How do I enable tracing and message logging in WCF?

To activate message logging, you must add a trace listener to the System. ServiceModel. MessageLogging trace source and set attributes for the <messagelogging> element in the configuration file. The following example shows how to enable logging and specify additional options.

How do I enable WCF tracing on client?

ServiceModel. MessageLogging trace source records all messages that flow through the system. Tracing is not enabled by default. To activate tracing, you must create a trace listener and set a trace level other than "Off" for the selected trace source in configuration; otherwise, WCF does not generate any traces.

How do I open a WCF trace file?

To open a trace file Start Service Trace Viewer by using a command window to navigate to your WCF installation location (C:\Program Files\Microsoft SDKs\Windows\v6. 0\Bin), and then type SvcTraceViewer.exe .

How do I turn off tracing in WCF?

If you want to disable the trace source, you should use the logMessagesAtServiceLevel , logMalformedMessages , and logMessagesAtTransportLevel attributes of the messageLogging element instead. You should set all these attributes to false.


1 Answers

Try to add:

<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />

in your diagnostics node, under messageLogging.

like image 200
David Brabant Avatar answered Oct 07 '22 12:10

David Brabant