logging 2 files every day with log4net
So what I wanna do is log two separate files on a daily basis. I'm new to log4net so what I did was usual stuff.. google and google until it works :) and everything works fine, but I can't make it log files every day.
Here is my code:
web.config:
<log4net>
<appender type="log4net.Appender.RollingFileAppender" name="AllApp">
<file value="C:\\myLogs\\App.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<layout type="l开发者_C百科og4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender type="log4net.Appender.RollingFileAppender" name="ServiceLog">
<file value="C:\\myLogs\\ServiceLog.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="AllApp" />
</root>
<logger name="ServiceLog">
<priority value="DEBUG" />
<appender-ref ref="ServiceLog" />
</logger>
</log4net>
and in my log class:
public static class LogProvider
{
static ILog log;
static LogProvider()
{
log4net.Config.XmlConfigurator.Configure();
log = LogManager.GetLogger("ServiceLog");
}
I'm probably doing something wrong but whatever I try it ends up in failure.
Try setting the rolling style like this:
<rollingStyle value="Date" />
so i guess there was no problem at all.. i just wasnt familiar with ways of date logging in log4net.. what log4net does is it leaves todays log undated (for example.. all this i log today will be stored in App.log, but tomorrow log4net will shift todays logs to App.logYYYYMMDD)
精彩评论