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

发布于 2024-09-06 05:58:28 字数 160 浏览 3 评论 0原文

我在应用程序中使用 Log4Net API 来记录任何重要事件或信息,并将异常记录到数据库中。

使用Log4Net API时可能会出现异常;如果它无法执行登录到数据库的操作,那么这个异常将如何存储?如果 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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-09-13 05:58:28

Log4net 将默默地失败,以便应用程序的主要功能不会受到干扰。如果您有一个绝对需要在数据库中存在的事件,那么您应该将其作为业务逻辑的一部分,即自己将其写入数据库。

如果您坚持为此使用 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文