Wednesday, January 30, 2008

Asynchronous logging using Logging Application Block

A quick search in the web for asynchronous logging using Logging Application Block revealed that there is only one way of doing it, using MSMQ and DistributorService.


I don’t have the option of using MSMQ for my application. So I put together a small solution for this problem using Jon Skeet’s asynchronous helper class called ThreadUtil [Thanks Jon]. The helper class has a method "FireAndForget" through which we can make an asynchronous calls without worrying about leaking handles. The helper class takes care of calling the EndInvoke and closing the waitHandle.


My solution is to use the helper class and make asynchronous calls to the Logging application block.


The sample can be downloaded from:

http://cid-0476ca5e9f26e63c.skydrive.live.com/self.aspx/Public/Documents/AsynchLogging.zip

Update:
In the asynchronous helper class the call to EndInvoke should be wrapped with in a try catch block. If not & if there is an exception while running the asynchronous method, it will be raised by the runtime when we call EndInvoke. If the exception is not handled at this point it would crash the whole application!

The new updated sample can be downloaded from:
http://cid-0476ca5e9f26e63c.skydrive.live.com/self.aspx/Public/Documents/AsynchLogging_Updated.zip

0 comments:

Saravanan Kanagaraj