命令 log4net 执行其附加程序
假设我的 .log4net.config 文件中有以下附加程序引用配置:
<root>
<level value="ALL"/>
<appender-ref ref="ColoredConsoleAppender" />
<appender-ref ref="EventLogAppender"/>
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="MyCustomAppender" />
</root>
log4net 是否在单个线程(即调用应用程序用于调用 ILog.* 方法的同一线程)上串行调用这些附加程序。如果是这样,它调用每个附加程序的顺序是什么?是否按照
Let's say I have the following appender references configuration in my .log4net.config file:
<root>
<level value="ALL"/>
<appender-ref ref="ColoredConsoleAppender" />
<appender-ref ref="EventLogAppender"/>
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="MyCustomAppender" />
</root>
Does log4net invoke these appenders serially on a single thread (i.e. the same thread that the calling application used to call the ILog.* method). And if so, what order does it invoke each appender? Is it done in the same order as they are defined in the <root> element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此链接(在“自定义附加程序:添加目标”部分中),log4net按照 Appender 在配置文件中出现的顺序执行它们。此外,Appender 是同步执行的。我不知道作者是不是log4net专家,但是这篇文章读起来足够好。
According to this link (in the section on Custom Appenders: Adding Destinations), log4net executes the Appenders in the order in which they appear in the config file. Also, the Appenders are executed synchronously. I don't know if the author is a log4net expert or not, but the article reads well enough.
虽然我找不到链接中所述内容的任何独立确认,http://www.devx.com/dotnet/Article/32096/1954,无论是在 log4net 站点还是通过进一步谷歌搜索,我已经更改了我的顺序根据文章,配置文件中的附加程序如下所示。
也许根元素是排序的关键元素,我也更改了 log4net 元素中附加程序元素的顺序
我的推理是,在严重失败的情况下,记录到 Windows 事件日志将比记录到 Windows 事件日志更成功写入文件(可能会说这是更重要的信息?)
While I couldn't find any independent confirmation of what was stated in link,http://www.devx.com/dotnet/Article/32096/1954, either at the log4net site or through further googling I have changed the order of my appenders in configuration file as shown below based on the article.
Maybe the root element is the critical element to order by I changed order of appender elements in log4net element as well
My reasoning is that in a critical failure scenario logging to windows event log is going to have more success than writing to file (and could be argued it is more important info?)