简体   繁体   English

Log4Net Root配置设置正在将文件级别混合到附加程序

[英]Log4Net Root config set-up is mixing file levels to appenders

I am having some trouble with the following root config setup: 我在以下root设置中遇到了一些麻烦:

<root>
  <level value="INFO" />
  <appender-ref ref="file-appender-info" />

  <level value="WARN" />
  <appender-ref ref="file-appender-warn" />

  <level value="ERROR" />
  <appender-ref ref="file-appender-error" />

  <level value="DEBUG" />
  <appender-ref ref="ConsoleAppenderStandard" /> 
</root>

It is writing all the levels of logs into ALL of the file Appenders. 它将所有级别的日志写入所有文件Appenders中。

So for example info-log.txt has logs from Log.Warn and Log.Error 因此,例如info-log.txt具有来自Log.Warn和Log.Error的日志

Im sure I have a simple issue with the layout of the config, but I cant seem to find out what it is. 我确定我对配置的布局有一个简单的问题,但是我似乎无法找出它是什么。

You are defining the level of logging repeatedly in the root, which then keeps only the latest one and uses it for all appenders. 您正在根中重复定义日志记录级别,然后仅保留最新级别并将其用于所有附加程序。 Only one level can exist for one logger. 一个记录器只能存在一个级别。

If you want to filter each level to one appender, declare all appenders in the root and use a LevelMatchFilter on each appender to have only one level type pass into each appender. 如果要将每个级别筛选为一个附加程序,请在根目录中声明所有附加程序,并在每个附加程序上使用LevelMatchFilter以便仅将一个级别类型传递给每个附加程序。

You may be interested in other filters, here is a list taken from the link above: 您可能对其他过滤器感兴趣,以下是来自上面链接的列表:

Here is a list of the filters available in the log4net distribution: 这是log4net发行版中可用过滤器的列表:

  • log4net.Filter.LevelMatchFilter Filters log events that match a specific logging level; log4net.Filter.LevelMatchFilter筛选匹配特定日志记录级别的日志事件; alternatively this can be configured to filter events that DO NOT match a specific logging level. 或者,可以将其配置为过滤与特定日志记录级别不匹配的事件。
  • log4net.Filter.LevelRangeFilter Similar to the LevelMatchFilter, except that instead of filtering a single log level, this filters on an inclusive range of contiguous levels. log4net.Filter.LevelRangeFilter与LevelMatchFilter相似,除了不过滤单个日志级别,而是在包含范围的连续级别上进行过滤。
  • log4net.Filter.LoggerMatchFilter Filters log events based on the name of the logger object from which they are emitted. log4net.Filter.LoggerMatchFilter根据发出事件的记录器对象的名称过滤日志事件。
  • log4net.Filter.StringMatchFilter Filters log events based on a string or regular expression match against the log message. log4net.Filter.StringMatchFilter根据与日志消息匹配的字符串或正则表达式过滤日志事件。
  • log4net.Filter.PropertyFilter Filters log events based on a value or regular expression match against a specific context property. log4net.Filter.PropertyFilter根据与特定上下文属性匹配的值或正则表达式过滤日志事件。
  • log4net.Filter.DenyAllFilter Effectively drops all logging events for the appender. log4net.Filter.DenyAllFilter有效地删除附加程序的所有日志记录事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM