How to instrument custom code that runs in Biztalk Server with tracing.
Biztalk tracing is frequently used by PSS to troubleshoot issues with Biztalk Server. One problem however is that in many cases Biztalk Server itself is not the root cause of the problem, rather, custom code running within the btsntsvc.exe service is the problem. In other words, there may be an orchestration which contains an expression which creates an object from custom code. The custom code hits an exception and all that is seen in the Biztalk trace is that the orchestration failed.
If you ever provide biztalk traces to PSS to tshoot issues which may arise from your code, you can instrument your code like the following to output the exception to the trace.
catch(Exception ex)
{
Microsoft.XLANGs.RuntimeTypes.Trace.Tracer.TraceMessage(Microsoft.XLANGs.RuntimeTypes.TraceLevel.Info,CustomComponent: Exception {0} at {1}", ex.Message, ex.StackTrace);
}
In order to do this, you must reference the Microsoft.XLANGs.RuntimeTypes assembly from your project.
Another example: Say you are making a webservice call from your code and not using the SOAP adapter. You could instrument the code as follows.
Microsoft.XLANGs.RuntimeTypes.Trace.Tracer.TraceMessage(Microsoft.XLANGs.RuntimeTypes.TraceLevel.Info, "CustomComponentWebservice call started");
Microsoft.XLANGs.RuntimeTypes.Trace.Tracer.TraceMessage(Microsoft.XLANGs.RuntimeTypes.TraceLevel.Info, "CustomComponent Webservice call returned");
You do have to be somewhat careful about using too much instrumentation as the size of Biztalk traces can become unmanageable, but in many cases tracing like the above would be helpful in resolving issues.