问题描述
我在应用程序中使用Log4Net API记录任何重要事件或信息以及将异常记录到数据库中.
I am using Log4Net API in my application to log any important event or information as well as logging my exceptions in database.
使用Log4Net API时可能会出现异常;如果无法执行登录数据库的操作,该异常将如何存储?如果Log4Net API无法执行日志记录,所有其他日志记录和异常日志记录将存储在哪里?
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将以静默方式失败,因此不会干扰应用程序的主要功能.如果您确实需要在数据库中拥有一个事件,则应将其纳入业务逻辑的一部分,即,将其自己写入数据库.
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.
如果您坚持为此使用log4net,则可以编写具有某些故障转移逻辑的追加程序,以确保所有事件(最终)都记录到数据库中.但是,这似乎不是一个好主意...
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.
这篇关于如果log4net追加程序无法在数据库中写入,如何记录此异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!