如何在 Log4Net 中设置每个附加程序的记录器特定级别

发布于 2024-09-11 13:07:00 字数 214 浏览 4 评论 0原文

给定两个附加程序:A1、A2 和多个记录器,其中一个是 L1

是否可以配置 log4net,以便:

A1 从所有记录器获取 DEBUG 及以上信息,例外 L1,它获取 INFO 及以上信息< br> A2 从所有记录器中获取 DEBUG 及以上,

我查看了附加器阈值、过滤器和我能想到的所有其他配置组合,但它们似乎都没有实现上述目标。

Given two appenders: A1, A2 and multiple loggers one of which is L1

Is it possible to configure log4net such that:

A1 gets DEBUG and above from all loggers except L1, for which it gets INFO and above
A2 gets DEBUG and above from all loggers

I have looked at appender threshold, filters, and every other configuration combination I can think of but none of them seem to accomplish the above.

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

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

发布评论

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

评论(2

平定天下 2024-09-18 13:07:00

您可以执行以下操作:

  1. 定义两个不带任何过滤器的附加程序(A1、A2)
  2. 创建一个 BufferingForwardingAppender,转发到 A1 并在级别 >= INFO 上进行过滤
  3. 创建一个 BufferingForwardingAppender,转发到 A2(无过滤器或 >= DEBUG) )
  4. 配置root logger使用appender A1, A2
  5. 配置L1 logger不继承appender (additivity = false);引用两个 BufferingForwardingAppender 相反,

我没有测试它,但我不明白为什么这不起作用。

You could do the following:

  1. Define your two appenders (A1, A2) without any filter
  2. Create a BufferingForwardingAppender, that forwards to A1 and filters on level >= INFO
  3. Create a BufferingForwardingAppender, that forwards to A2 (no filter or >= DEBUG)
  4. Configure the root logger to use appenders A1, A2
  5. Configure the L1 logger to not inherit appenders (additivity = false); reference the two BufferingForwardingAppender instead

I did not test it, but I do not see why this would not work.

2024-09-18 13:07:00

根据文档:

过滤器形成事件必须通过的链。沿途的任何过滤器都可以接受事件并停止处理、拒绝事件并停止处理或允许事件进入下一个过滤器。如果事件到达过滤器链的末尾而没有被拒绝,则它会被隐式接受并被记录。

所以看起来像这样的东西会起作用(未经测试的伪代码):

A1
    Level >= INFO:  Accept
    Logger == L1: Deny
    Level >= DEBUG: Accept
    DenyAll

A2
    Level >= DEBUG: Accept

According to the docs:

Filters form a chain that the event has to pass through. Any filter along the way can accept the event and stop processing, deny the event and stop processing, or allow the event on to the next filter. If the event gets to the end of the filter chain without being denied it is implicitly accepted and will be logged.

So it seems that something like this would work (untested pseudo-code):

A1
    Level >= INFO:  Accept
    Logger == L1: Deny
    Level >= DEBUG: Accept
    DenyAll

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