Logging using existing transaction

Topics: Logging Application Block
Oct 2, 2009 at 6:54 PM

Hi there:

I have logging application block integrated in my busines layer. I have configured logging to use a database listener.

Now i'm making some testing and it was a big surprise to notice that the database listener was using the transactions that some manager class has created.

I'm wondering if there is any configuration setting to tell logging not to use the current transaction, because i'd like my logs to be there in the database even if an exception is raised and the business DB operations are rollbacked.

Thanks in advance for any answer.



Oct 2, 2009 at 8:40 PM

Personally, I'm a big fan of using the MsmqTraceListener from my apps and then having the Enterprise Library Distributor Service handle routing messages to the DB, text files, email, etc.  It avoids issues like the one your having (assuming your queue is not transactional).  Additionally, your app isn't waiting on logging tasks to complete before continuing on to execute your business logic.  

Other than that, I suppose you could wrap each call to Logger.Write in a TransactionScope with the TransactionScopeOption.Suppress option.

Just my two cents.  good luck,