views:

96

answers:

1

Hi,

we are using log4net with a AdoNetAppender to write critical logs into an database. Since the AdoNetAppender is a subclass of the BufferedAppender there is a possibility to enable queuing of log events. What I'd like to do is to save the backup & restore the log buffer to a local file, so that no log entry can get lost it the database is down or the application crashes.

Does somebody know how to this?

+1  A: 

Don't think you can save the buffer without writing some code yourself. What I rather would suggest is sending the logs to both a AdoNetAppender and a RollingFileAppender. The first will ensure your regular logging to database while the second will ensure that the latest logs are also written to disk.

Update: in light of your later comments I can see how logging to two different sources (one database and one local store, either a file or local database) gets tough to consolidate.

Imo you should absolutely use log4net for what it is best at: a tried and true framework for collection log data from the application and routing that data to receiving systems. Building a failover system on top of log4net though is not what it is designed for. For instance, there is no process model that can pick up the pieces after an application crash.

Instead, handle failover in the receiving system. Failover at the database level and the network level gets you a long way, still you are not guaranteed 100% uptime. By logging to a local store and then have a process picking up the logs and shipping it to the database would minimize the risk for log data being lost, and at the same time you avoid having to consolidate logs from two different stores. Even better, logging is still simple and fast and thus have a low impact on the application.

An alternative would be logging to a local database and having a database job pull the data into the master database. You could also use queuing. There is a sample MsmqAppender out there to get you started. If you're using MS SQL Server you could even use the Service Broker for its queuing abilities.

Peter Lillevold
For me it looks like extending the AdoNetAppender is more efford than writing a complete custom database logger with a serialized queue to ensure no log entries are lost.
Alexander
@Alexander: are you saying that you don't need the buffering feature of AdoNetAppender? If so, then why not set BufferSize to 0, this will effectively make the appender log synchronously without buffering.
Peter Lillevold
...still, to still be able to log while the database is down you should use a file appender logging to the local file system.
Peter Lillevold
It's not a simple debug log. We use the AdoNetAppender to log user critical user actions in a database. Having half of the log entries in the database and the other half in a file is no option.log4net maybe is not designed for this...
Alexander