开发者

log4net save buffer from BufferedAppender

开发者 https://www.devze.com 2022-12-22 03:13 出处:网络
we are using log4net with a AdoNetAppender to write critical logs into an database. Since the AdoNetApp开发者_运维百科ender is a subclass of the BufferedAppender there is a possibility to enable queui

we are using log4net with a AdoNetAppender to write critical logs into an database. Since the AdoNetApp开发者_运维百科ender 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消