log4net 写入mysql,如果log4net追加程序无法在数据库中写入,如何记录此异常?

I am using Log4Net API in my application to log any important event or information as well as logging my exceptions in database.

There might be an exception while using Log4Net API; if it fails to perform logging into database then how will this exception be stored? Where will all other logging and exception logging be stored in case the Log4Net API fails to perform logging?

解决方案

Log4net will fail silently so that the primary function of the application is not disturbed. If you have an event that you absolutely need to have in the database, the you should make it part of your business logic i.e. write it yourself to the database.

If you insist using log4net for this, then you could write an appender that has some fail over logic that makes sure that all events get logged to the database (eventually). However this does not seem to be a good idea...

As for normal logging: In order to ensure that I have logs I usually use a rolling file appender in addition to other appenders. This way I can be quite sure that in the worst case I have the log available in a file.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值