我有一个C#应用程序,当我尝试将日志输出定向到1个日志文件时,它会同时写入两个日志文件。
c#代码:
public static ILog log { get; set; }
log = LogManager.GetLogger("log1");
log.Info("foo");
app.config:
<log4net>
<logger name="log1" additivity="false">
<appender-ref ref="RollingLogFileAppender1" />
</logger>
<logger name="log2" additivity="false">
<appender-ref ref="RollingLogFileAppender2" />
</logger>
<appender name="RollingLogFileAppender1" type="log4net.Appender.RollingFileAppender">
<file value="log1.txt" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
</layout>
</appender>
<appender name="RollingLogFileAppender2" type="log4net.Appender.RollingFileAppender">
<file value="log2.log" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
</layout>
</appender>
</log4net>
无论我尝试log1还是log2,都会发生这种情况。它无论写给两个。 有人知道如何解决这个问题吗?谢谢!