我对log4net很新,我正在尝试创建几个文件并使用我的方法调用相应地记录它们,这是我的代码:
private static readonly ILog firstlog = LogManager.GetLogger("Data"); private static readonly ILog secondlog = LogManager.GetLogger("General");
然后我这样记录:
firstlog.Info("some message"); secondlog.Info("some message");
这是我的配置文件:
<appender name="General" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="C:\logs\myfile1.log"/>
<param name="Threshold" value="DEBUG"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="10MB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %method %-5level %logger – %message%newline"/>
</layout>
</appender>
<appender name="Data" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="C:\logs\myfile2.log"/>
<param name="Threshold" value="DEBUG"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="10MB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %method %-5level %logger – %message%newline"/>
</layout>
</appender>
<logger name="general">
<appender-ref ref="General"/>
</logger>
<logger name="data">
<appender-ref ref="Data"/>
</logger>
<root>
<appender-ref ref="Data"/>
</root>
它们都记录在一个文件中,其他两个文件都是空的。为什么是这样? 我做错了什么?
答案 0 :(得分:0)
尝试删除该行
<appender-ref ref="Data"/>
来自节点的......