这是我们正在使用的设置,不知道为什么这不起作用。
班级档案
const string conpath = @"configfiles\log4net.config";
XmlConfigurator.Configure(new FileInfo(conpath));
的AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile = @"configfiles\log4net.config", Watch = true)]
log4net.config
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<!-- appender section -->
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{MM/dd/yyyy HH:mm:ss.fff}]: %message%newline%exception"/>
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%m%n%exception" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString">
<conversionPattern value=".\LogFiles\log" />
</file>
<appendToFile value="true" />
<staticLogFileName value="false" />
<rollingStyle value="Date" />
<datePattern value=" - yyyy.MM.dd'.txt'"/>
<layout type="log4net.Layout.PatternLayout">
<header value="[LOG FILE STARTED] " />
<conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %message%newline" />
<footer value=" [LOG FILE FINISHED] " />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="DebugAppender"/>
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>