How to log this exception if log4net appender fails to write in database?

浪子不回头ぞ 提交于 2019-12-22 09:24:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3065179/how-to-log-this-exception-if-log4net-appender-fails-to-write-in-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!