posts - 3, comments - 2, trackbacks - 3

My Links

News



Archives

Using TraceSource for Diagnostic Tracing and Events Logging in BizTalk Server 2006

Diagnostic tracing and events logging with BizTalk can be achieved using the Log4Net Serializable “log4net.Ext.Serializable” written by Scott Colestock which includes AdoNet appender to write events to a database alongside a large list of appenders which can be very useful depending on your requirement. One good thing about this is the ability to view the events using the Debug View which proved useful to a lot of my colleagues. There are other Logging tools in C# such as the Enterprise Library and other open source (Check the Resources section below for all the links).

 

Yet, for a quick and easy diagnostic tracing and events logging, I used TraceSource class in System.Diagnostics of .NET framework. The good thing about TraceSource is the ability to deal with your solutions in layers so you should easily be able to manipulate the config file to switch off the logging in some layers of your application as required without having to make a change to the code itself or BizTalk application similar to log4net but in a simpler form. The steps are as follow:

 

Create your own Serializable class to utilise TraceSource class. Something like:

 

    [Serializable]

    public class TraceEvents

    {

        public static void OutputEvent()

        {

            TraceSource logEvents = new TraceSource("TestTraceSource");

            logEvents.TraceEvent(TraceEventType.Warning, 1000, "Test Trace Source...");

        }

    }

 

-          Specify a strong key in the AssemblyInfo.cs

-          Build and GAC the dll

-          You may want to add it to the Public assemblies folder of Visual Studio 2005 for easier access

 

Then, modify BTSNTSvc.exe.config to include the <system.diagnostics> tag within the <configuration> tag as follow:

 

<system.diagnostics configSource="log.config"></system.diagnostics>

 

Create a separate config/text “log.config” file in BizTalk directory (C:\Program Files\Microsoft BizTalk Server 2006) with the same name specified above containing all the TraceSource settings you wish to include as follow:

 

<system.diagnostics>

    <sources>

      <source name="EventLogTraceSource" switchValue="All">

        <listeners>

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

          <add name="eventLogListener" />

          <add name="fileLogListener" />

        </listeners>

      </source>

    </sources>

    <sharedListeners>

      <add initializeData="C:\TestTraceSource.svclog"

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

        name="fileLogListener" />

      <add initializeData="TestTraceSource"

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

        name="eventLogListener"/>

    </sharedListeners>

    <trace autoflush="true" />

  </system.diagnostics>

 

(Note: the following example is designed to write entries to both the event viewer and log file. The log file “C:\TestTraceSource.svclog” can be viewed using the Microsoft Service Trace Viewer that is available in the Tools directory of Microsoft Windows SDK):

 

Now, create a reference to the dll in your BizTalk project and call OutputEvent method from the orchestration: xxx.xxx.TraceEvents.OutputEvent();

 

When running the orchestration, you should be able to see events written into a log file in the C drive and also in the event viewer.

 

 

Resources:

-          TraceSource: http://msdn2.microsoft.com/en-us/library/system.diagnostics.tracesource.aspx

-          Log4Net: http://logging.apache.org/log4net/

-          log4net.Ext.Serializable: http://www.traceofthought.net/PermaLink,guid,62b858b4-d8ba-4fc4-92aa-35a4ff1ba00a.aspx

-          Logging Tools in C#: http://csharp-source.net/open-source/logging

-          Enterprise Library 2.0 & 3.0: http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=1368

  

Print | posted on Thursday, February 08, 2007 10:42 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: