如何配置 log4net 进行回退
这就是我的情况。我已经使用 log4net 成功实现了远程系统日志记录。但是,据我测试,如果 syslog IP 无效,所有消息都不会记录在任何地方,并且不会引发异常。它只是什么都不做。
因此,最好有某种后备措施。假设如果写入系统日志失败,则写入文件或数据库。
log4net 可以做到这一点吗?或者我是否必须将其配置为同时登录到两个位置?
This is my situation. I have successfully implemented logging to remote syslog using log4net. However, as far as I could test, if syslog IP is not valid, all messages will not log anywhere and no exception is raised. It just does nothing.
Hence, it would be nice to have some sort of fallback. Let's say if writing to syslog fails, write to file or to database.
Is that even possible with log4net? Or would I have to configure it to log to two locations at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不能通过配置来做到这一点。此问题在 log4net 功能待办事项中开放。
如果您的应用程序可以消耗日志记录开销,那么最简单的解决方案是默认记录到备用附加程序。
或者,您可以尝试将您正在使用的附加程序包装在自定义附加程序中,并在系统日志附加程序抛出异常时实现回退方案。如果它不默默地吞噬它们的话。
来自 log4net 常见问题解答:
第三种选择是查看附加程序的源代码,看看是否可以分叉它并在那里进行必要的自定义。
I don't think you can do this by configuration. This issue is open in the log4net feature backlog.
If your application can eat the logging overhead, the easiest solution would be to log to an alternative appender by default.
Alternatively you could try to wrap the appender you're using in a custom appender, and implement the fallback scenario if the syslog appender throws an exception. If it doesn't swallow them silently.
From log4net FAQ:
Third option would be to look into the source code of your appender and see if you can fork it and do the necessary customizations there.