Tuesday, February 17, 2015

log4net AdoNetAppender stops logging / does not recover if database connection is lost / database is down, ReconnectOnError

I use the Apache log4net AdoNetAppender to log information from my application into a SQL database. In case, the network connection to the database is lost or the database is down for some reason, the AdoNetAppender quits logging (forever) to the database and does not recover even if the database is online again.

How-I-fixed-it:
I found the right hints here:
https://www.mail-archive.com/log4net-user@logging.apache.org/msg04655.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.ReconnectOnError.html

Add the tag:

to the log4net XML config file:



   


Keep in mind, that it then tries to reconnect to the database until the connect times out. This blocks the thread of the application!

You can add:
Connect Timeout=1 to the connectionString  property to Limit the blocking to 1 second:
   
   
   
  



   
   
   
   
  

No comments:

Post a Comment