命令 log4net 执行其附加程序

发布于 2024-10-07 09:23:25 字数 446 浏览 4 评论 0原文

假设我的 .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 技术交流群。

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

发布评论

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

评论(2

一曲琵琶半遮面シ 2024-10-14 09:23:25

根据此链接(在“自定义附加程序:添加目标”部分中),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.

青巷忧颜 2024-10-14 09:23:25

虽然我找不到链接中所述内容的任何独立确认,http://www.devx.com/dotnet/Article/32096/1954,无论是在 log4net 站点还是通过进一步谷歌搜索,我已经更改了我的顺序根据文章,配置文件中的附加程序如下所示。

也许根元素是排序的关键元素,我也更改了 log4net 元素中附加程序元素的顺序

我的推理是,在严重失败的情况下,记录到 Windows 事件日志将比记录到 Windows 事件日志更成功写入文件(可能会说这是更重要的信息?)

<log4net threshold="ALL">
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
        <!-- Make stuff go here -->
    </appender>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <!-- Make stuff go here -->
    </appender>
    <root>
      <appender-ref ref="EventLogAppender" />
      <appender-ref ref="RollingFileAppender" />
    </root>
</log4net>

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?)

<log4net threshold="ALL">
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
        <!-- Make stuff go here -->
    </appender>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <!-- Make stuff go here -->
    </appender>
    <root>
      <appender-ref ref="EventLogAppender" />
      <appender-ref ref="RollingFileAppender" />
    </root>
</log4net>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文