ETW Tracing from the BizTalk Customer Advisory Team (CAT) is now increasingly used by developers for tracing in BizTalk applications. In the ESB toolkit it’s not implement so I wanted to see if it’s difficult to create a custom Messaging Service that uses ETW Tracing.
Steps
On MSDN on the Creating a Custom Itinerary Messaging Service page is explained how to create a custom Messaging Service. The following methods and properties are required:
|
In the code example on MSDN is only the ExecuteRoute method shown that is called by the Execute method. This method is not needed when you create your own Messaging Service. Therefore I used Reflector to disassemble the Routingservice to get also the other methods and properties. |
On the Best Practices for Instrumenting High Performance BizTalk Solutions blog post from the CAT team you can get the source code for the ETW tracing. |
In the example below is the “ExecuteTracing” method shown that is specific for the Tracing Service: |
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }public IBaseMessage ExecuteTracing(IPipelineContext context, IBaseMessage msg,
string resolverString) { // A call to the TraceIn method at the very beginning of an instrumented code. Guid g = TraceManager.PipelineComponent.TraceIn(); IBaseMessage message; if (context == null) { throw new ArgumentNullException("context"); } if (msg == null) { throw new ArgumentNullException("msg"); } try { // Get context properties from message string interchangeID = msg.Context.Read(BtsProperties.InterchangeID.Name,
BtsProperties.InterchangeID.Namespace) as string; string messageType = msg.Context.Read(BtsProperties.MessageType.Name,
BtsProperties.MessageType.Namespace) as string; string receivePortName = msg.Context.Read(BtsProperties.ReceivePortName.Name,
BtsProperties.ReceivePortName.Namespace) as string; string inboundTransportLocation = msg.Context.Read(BtsProperties.InboundTransportLocation
.Name, BtsProperties.InboundTransportLocation.Namespace) as string; // Writes an information message to the trace. TraceManager.PipelineComponent.TraceInfo("[InterchangeID: {0}]", interchangeID); TraceManager.PipelineComponent.TraceInfo("[MessageType: {0}]", messageType); TraceManager.PipelineComponent.TraceInfo("[ReceivePortName: {0}]", receivePortName); TraceManager.PipelineComponent.TraceInfo("[InboundTransportLocation: {0}]", inboundTransportLocation); message = msg; } catch (Exception exception) { EventLogger.Write(MethodBase.GetCurrentMethod(), exception); // Writes the exception details to the trace. TraceManager.PipelineComponent.TraceError(exception, true, g); throw; } // Writes an informational event into the trace log that a method is about to complete. TraceManager.PipelineComponent.TraceOut(g, "[Completed trace]"); return message; }.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
In the esb.config in “C:\Program Files\Microsoft BizTalk ESB Toolkit 2.1” you have to add your custom Itinerary Service. |
Now you can create an Itineray with the custom TracingService: |
The created itinerary can be tested with the Itinerary Test Client that is located in the ESB Toolkit sample applications |
Trace output: |
Conclusion
In principle, it’s not very difficult to create a custom Messaging Service. Still it took a lot of time to create the service and to got the itinerary running because it’s not so well-documented,.
You can download the sample Messaging Service with the source code here:
http://code.msdn.microsoft.com/Creating-a-Custom-44338c2e