log4net, ADONetAppender, TransactionScope, Distributed transaction completed

It seems that if you have an log4net ADONetAppender configured and you try and log within the scope of a distributed transaction, the ADONetAppender is included in the transaction,  and remembers it because the ADONetAppender caches the connection. This means that the next attempt to log after the transaction completes will fail because the transaction the connection refers to has already completed.
 
The result usually looks like this:
 
System.Data.SqlClient.SqlException: Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.
 
On your connection string within your ADONetAppender config section set "Enlist=false". You do not want to participate in a DTS transaction (after all if it fails you probably still want to log that failure).
 
 
Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s