I'm very new to the log4net, and I am trying to create several files and log to them accordingly with my method calls and here is my code:
private static readonly ILog firstlog = LogManager.GetLogger("Data"); private static readonly ILog secondlog = LogManager.GetLogger("General");
and then I log like this:
firstlo开发者_如何学JAVAg.Info("some message"); secondlog.Info("some message");
and here is my configuration file:
<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>
And they are all logged in one file and the other two files are empty. Why is this? What am I doing wrong?
Try removing the line
<appender-ref ref="Data"/>
from the node...
精彩评论