、百度一下log4dll下载
、webconfig 里的<configSetions>节点中添加 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
、增加节点内容如下:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log//" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value="yyyy-MM-dd".log"" />
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d 系统异常: %m%n%n" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
、在引用log4类库、项目中里的AssemblyInfo类中添加日志监视
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
、测试日志代码
ILog log = log4net.LogManager.GetLogger("LogFileAppender");
log.Error(ex);