|
1.在程序中添加引用:log4net.dll
2.在AssemblyInfo.cs文件中添加代码行:
[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension = "config", Watch = true)]
3.在app.config文件中添加代码行:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net-net-1.0"/>
</configSections>
<log4net>
<appender name="LogFileByDate" type="log4net.Appender.RollingFileAppender">
<file value="C:\DCLog\"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM/yyyy-MM-dd.LOG"/>
<staticLogFileName value="false"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%-5level] %n -- %m%n"/>
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="LogFileByDate"/>
</root>
</log4net>
</configuration>
4.在输出文件中添加代码行:
ILog log = LogManager.GetLogger("MyLogger");
log.Info("test"); |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|