我的log4net 1.2.9 的配置文件和如何配置程序的说明
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
<logger name="PenavicoxmLogger">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
<root>
<level value="ALL" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="Penavicoxm.log.txt" />
<param name="datePattern" value="MM-dd HH:mm" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log\Penavicoxm" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value=".yyyyMMdd'.txt'" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
</log4net>上面配置文件主要演示两种形式
1.单配置文件 LogFile ,日志文件存放在网站的根目录,日志文件PenavicoxmLog.txt,需要对这个文件有写的权限。
2.每日一个日志文件 RollingLogFile,日志文件存放在网站的log目录,需要asp.net有写的权限,日志格式 Penavicoxm.日期.txt
web:
<1>assembly info:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch=true)]
<2>然后拷贝log4net.config到web的目录
<3>在gloable.asax 的application_start的事件
log4net.Config.XmlConfigurator.Configure( new FileInfo("log4net.config") );
<4>如果要记录什么日志
用ApplicationLog.WriteInfo() WriteError()就可以记录
winform:
<1>assembly info:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch=true)]
<2> 在入口函数
[STAThread]
private static void Main()
{
log4net.Config.XmlConfigurator.Configure( new FileInfo("log4net.config") );
}
<4>然后拷贝log4net.config到bin的debug/release的目录
或者修改目标项目的属性
项目的属性-通用属性-预生成事件命令行
在那里输入copy $(ProjectDir)log4net.config $(TargetDir)log4net.config
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
1.单配置文件 LogFile ,日志文件存放在网站的根目录,日志文件PenavicoxmLog.txt,需要对这个文件有写的权限。
2.每日一个日志文件 RollingLogFile,日志文件存放在网站的log目录,需要asp.net有写的权限,日志格式 Penavicoxm.日期.txt
web:
<1>assembly info:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch=true)]
<2>然后拷贝log4net.config到web的目录
<3>在gloable.asax 的application_start的事件
log4net.Config.XmlConfigurator.Configure( new FileInfo("log4net.config") );
<4>如果要记录什么日志
用ApplicationLog.WriteInfo() WriteError()就可以记录
winform:
<1>assembly info:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch=true)]
<2> 在入口函数
[STAThread]
private static void Main()
{
log4net.Config.XmlConfigurator.Configure( new FileInfo("log4net.config") );
}
<4>然后拷贝log4net.config到bin的debug/release的目录
或者修改目标项目的属性
项目的属性-通用属性-预生成事件命令行
在那里输入copy $(ProjectDir)log4net.config $(TargetDir)log4net.config