问题
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