使用备份附加程序进行日志记录
如果当前的日志框架出现问题,是否有任何 .NET 日志框架能够切换附加程序。实际上我想要的是:
如果我正在使用数据库附加程序,并且当数据库出现问题时(例如服务器出现故障,断电...)我想切换到第二个附加程序(例如登录到文件)。
该能力是否具有以下之一:log4net、NLog、Enterprise Library?我一直在寻找这个,但没有运气。
Is there any .NET logging framework that have ability to switch appender if something is wrong with current one. Actually what I want is following:
If I'm using database appender and when something goes wrong with database (e.g. server goes down, lose power...) I want to switch to second appender (e.g. which log into file).
Does this ability have one of following: log4net, NLog, Enterprise Library? I was looking for this but no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为了完整起见:企业库支持可配置的错误特殊源,您可以在其中设置“附加程序”来记录出错的消息。配置完成后,无需任何编程即可运行。
唯一的缺点是,它实际上会以无法更改的特定格式记录发生的异常以及日志条目详细信息,因此不灵活。这对于故障排除很有用,但如果您想提取错误的日志消息并将其导入原始日志记录目标(尽管格式已知,因此可以解析),则可能不太理想。
For completeness: Enterprise Library supports a configurable Error Special Source where you can set an "appender" to log messages that have errored. Once configured this just works without any programming.
The only downside is that it will actually log the exception that occurred along with the Log Entry details in a specific format that cannot be changed so it is not flexible. This is good for troubleshooting but it might not be ideal if you want to extract errored log messages and import them into the original logging destination (although the format is known so it would be possible to parse).
据我所知,log4net 目前不支持备份附加程序,log4net 功能积压中存在(或曾经?)一个未解决的问题。但我认为名为 FallbackAppender 的项目正是您所需要的。
As far as I know log4net currently does not support backup appenders, there is (or was?) an open issue in the log4net feature backlog. But I think that the project called FallbackAppender does exactly what you need.
因为log4netContribute FallbackAppender没有按预期工作我进行了深入研究,发现这个能力有nLog。我测试了它,它工作起来就像一个魅力;)这是一个例子:
[app.config]
[code]
Because log4netContribute FallbackAppender is not working as expected I've made deep research and found that this ability has nLog. I tested it and it is working like a charm ;) Here is an example:
[app.config]
[code]
是的,Log4Net 允许您拥有多个日志目的地,例如:日志文件、电子邮件、数据库和事件查看器。
您可以更改应用程序的配置文件中的目标。您还可以同时运行多个 - 例如记录到事件查看器和数据库。
我总是建议默认设置两个日志目的地 - 以防其中一个出现问题。
Yes, Log4Net allows you to have multiple log destinations, such as: Log file, Email, Database, and Event Viewer.
You can change the destination in the application's config file. You can also run more than one at the same time - e.g. log to the Event Viewer and database.
I'd always recommend having two log destinations by default - in case one of the them has a problem.
NLog 允许您通过配置文件登录到多个目标。不要忘记将 ignoreFailures 设置为 true 以确保忽略任何安装/卸载失败:
请参阅 数据库目标 了解更多信息
编辑:您还可以创建自定义目标以在代码中实现此目的:
并将其用于:
请参阅此页面了解更多信息。
NLog allows you to log to multiple targets via a configuration file. Don't forget to set ignoreFailures to true to ensure that any install/uninstall failures are ignored:
See database target in the NLog documentation for more information
Edit: You could also create a custom target in order to achieve this in code:
and use it with:
See this page for more information.