English 中文(简体)
具有类似原体名称的元数据分类
原标题:log4net logger hierarchy with similar log root names

我是否在这里看到了ug,或者我是否对这一组合做了一些错误?

<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%message%newline" />
  </layout>
</appender>
<logger name="MyApp.Common">
  <level value="WARN" />
  <appender-ref ref="ConsoleAppender" />
</logger>
<logger name="MyApp.Common.Namespace.SomeGenericClass`1">
  <level value="INFO" />
  <appender-ref ref="ConsoleAppender" />
</logger>

假设我按照标准“......DeclaringType”命名计划命名我的记录仪,我在此期望的是,我的评估书规定的所有事项。 共同名称空间只要带上WARN或更高名称,就将进入该群岛。 某些基因组别的1号中的任何数据,如果其信息或更高(如果由于WARN的记录,其数据为WARN或更高两次)。

What is happening is that anything in SomeGenericClass`1 that gets logged in INFO will be piped out to the console twice, instead of the expected once. If I remove the more specific logger, nothing gets logged, and if I remove the less specific logger, things only log once, both as expected. In addition, reversing the order of the loggers in the config file does nothing (as I would expect, since I would guess that order doesn t matter).

Did I find a bug here, or am I missing something important in how the hierarchy works?

问题回答

我在使用多个伐木点方面的实验经验是,日志4net将使用你在任何特定伐木中设定的最低水平。 因此,即使你在MyApp.Common使用MyApp.Common.SomeGenericClass中的INFO,在MyApp.Common中具体指明了WARN,却导致全球(?)水平下降至WARN。 因此,你从我的阿普切特进入。 Common as well as MyApp.Common.SomeGeneric 自信人ConsoleAppender上课两次。

我随后将获得一个子系列的原木,以单独存档。 你在你们的提问中说的并不是什么,而是包括你们想要做的事情。 我确实想把我的解决办法记录在我能再次为我谋利的地方。

我创建了两个不同的记录,如你前面的,但一个是根本的,它将同样发挥作用。 然后,我创建了两个不同的过滤器,每个过滤器在不同误差水平上,并在两个记录簿中分别提及。 我得到的是来自其他Namespace的航标,是另一个档案和所有其他文件。 该法典如下。

<log4net>
<logger name="OtherNamespace">
  <appender-ref ref="OtherNamespaceAppender"/>
</logger>
<root>
  <level value="WARN"/>
  <appender-ref ref="MyRollingFileAppender"/>
</root>
<appender name="MyRollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="C:ComanchemylogfileFor_%property{User}.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <threshold value="ERROR" />
  <countDirection value="3" />
  <maxSizeRollBackups value="2" />
  <maximumFileSize value="200KB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%-6level%utcdate{ABSOLUTE} – %location :: %message%newline" />
  </layout>
</appender>
<appender name="OtherNamespaceAppender" type="log4net.Appender.RollingFileAppender">
  <file value="C:ComancheOtherNamespace.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <threshold value="WARN" />
  <countDirection value="3" />
  <maxSizeRollBackups value="2" />
  <maximumFileSize value="200KB" />
  <staticLogFileName value="true" />
  <filter type="log4net.Filter.LoggerMatchFilter">
    <acceptOnMatch value="true" />
    <LoggerToMatch value="OtherNamespace" />
    <!-- set your class name here -->
  </filter>

  <filter type="log4net.Filter.DenyAllFilter" />

  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%-6level%utcdate{ABSOLUTE} :: %message%newline" />
  </layout>
</appender>

了解“除别外”是另一个名称空间,因此它没有被冲入其他Name航天日志,如果存在某种名称配对,它本可以这样做。 还指出,既然所有东西都继承了根基,如果我改变了WARN根指的投射器的伐木水平,我也会推延其他Namespace标志。 我想要实现的是,伐木比其他一切都更详细。

我认为,这应该做你们想要做的事情(而不是检验):

<logger name="MyApp.Common">
     <level value="WARN" />
     <appender-ref ref="ConsoleAppender" />
</logger>
<logger name="MyApp.Common.Namespace.SomeGenericClass`1">
     <level value="INFO" />  
</logger>

没有必要再次提及投递人,除非你将改为伪造。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签