Using WCF message logging and tracing

WCF provides a number of diagnostics features that can help you troubleshoot your applications. We will look at two of these: message logging and tracing.

  • Message logging: This enables you to log all the messages that are sent and received by the AOS. It allows you to see what data and parameters are in the messages being exchanged. In this way, it is similar to the logging functionality on the integration port, but it is all handled by WCF.
  • Tracing: This allows you to look at how messages flow between the client and service. Techniques such as activity propagation and correlation of messages allow you to keep track of the entire conversation between the client and service both at the service and transport level.

Both of these output to the .svclog files that you can analyze using the Service Configuration Editor.

Note

For this demonstration, we will use the Service Configuration Editor that is part of the Windows SDK. For more information, visit the Configuration Editor Tool (SvcConfigEditor.exe) page on MSDN at http://msdn.microsoft.com/en-us/library/ms732009(v=vs.100).aspx.

Configuring message logging and tracing

Message logging and tracing are both configured in the same place, so you will configure them both at the same time. To do this, modify the configuration file of the AOS by performing the following steps:

  1. Start the Service Configuration Editor.
  2. Go to File | Open | Config Fileā€¦ or press Ctrl + O.
  3. Select the Ax32Serv.exe.config process from the bin directory of your AOS, for example, C:Program FilesMicrosoft Dynamics AX60ServerAX60inAx32Serv.exe.config.
  4. When you are prompted with a warning, click on Yes to continue with opening the file.
  5. Navigate to the Diagnostics node and highlight it.
  6. On the right-hand side, click on Enable MessageLogging and Enable Tracing.
  7. Select the Message Logging node located under the Diagnostics node.
  8. On the right-hand side, set LogEntireMessage to True.
  9. Press Ctrl + S to save the configuration.

The result should look like the following screenshot:

Configuring message logging and tracing

As you can see, both message logging and tracing are now active. What this did was add the following nodes to the configuration file:

<system.diagnostics>
  <sources>
    <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,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="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:Program FilesMicrosoft Dynamics AX60ServerAX60inAx32Serv_messages.svclog"
      type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
      <filter type="" />
    </add>
    <add initializeData="C:Program FilesMicrosoft Dynamics AX60ServerAX60inAx32Serv_tracelog.svclog"
      type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
      <filter type="" />
    </add>
  </sharedListeners>
  <switches>
    <add name="ServiceTraceLevel" value="Off" />
  </switches>
  <trace autoflush="false" indentsize="4">
    <listeners>
      <add initializeData="Dynamics AX Services" type="System.Diagnostics.EventLogTraceListener"
        name="AxTraceListener">
        <filter type="" />
      </add>
    </listeners>
  </trace>
</system.diagnostics>

Analyzing service traces

Before you can take a look at the trace files, you first have to make sure to generate some service communication. In order to do this, execute the getAllTitles service operation of CVRTitleService as you have done many times in this chapter.

Analyzing message logging

The WCF trace file containing the message logging is located in the bin directory of the AOS where tracing has been enabled. The name of the file is Ax32Serv_messages.svclog. Double-click on it and it will open using the Microsoft Service Trace Viewer, as shown in the following screenshot:

Analyzing message logging

As you can see from the previous screenshot, the message that corresponds to the reply that the AOS sent to the .NET application has been selected. You can see the header and also the data of the message because we already set the LogEntireMessage property to True.

Analyzing tracing

The WCF trace file containing the tracing data is located in the bin directory of the AOS where the tracing has been enabled. The name of the file is Ax32Serv_tracing.svclog. Double-click on it and it will open using the Microsoft Service Trace Viewer, as shown in the following screenshot:

Analyzing tracing

While message logging gives emphasis to the content of the messages, tracing focuses more on the events that occur and the correlation between them. When combined with a trace from the client side, it allows you to trace WCF from end to end.

Note

There is much more to WCF message logging and tracing than we can cover here. For an in-depth view on how to configure it the best for your implementation, visit the Diagnostic Tracing and Message Logging page on MSDN at http://msdn.microsoft.com/en-us/library/dd788183.aspx.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.11.227