Log4Net: Multiple loggers

坚强是说给别人听的谎言 提交于 2019-12-04 17:43:38

问题


I have the following log4net configuration:

<log4net>
  <appender name="A1" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="C:\path1.log" />
  </appender>

  <appender name="A2" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="C:\path2.log" />
  </appender>

  <logger name="A1Logger">
    <level value="ALL" />
    <appender-ref ref="A1" />
  </logger>

  <logger name="A2Logger">
    <level value="ALL" />
    <appender-ref ref="A2" />
  </logger>

</log4net>

and then in code I do the following:

var logger1 = LogManager.GetLogger("A1Logger");
var logger2 = LogManager.GetLogger("A2Logger");

but both log to the same file C:\path1.log.

What am I doing wrong?


回答1:


Add the debug="true" attribute to the <log4net> element, my guess is that it is the missing <root> element that causes problems. You should always include the <root /> logger element.




回答2:


Seems that it was a weird debugging error. Right now it doesn't reproduce. My apologies.



来源:https://stackoverflow.com/questions/3470272/log4net-multiple-loggers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!