log4net配置与初始化
Posted GUOKUN
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了log4net配置与初始化相关的知识,希望对你有一定的参考价值。
1、配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<logger name="Weixin" additivity="false">
<level value="All" />
<appender-ref ref="AccountRollingFileAppender" />
</logger>
<appender name="AccountRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Weixin.log" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Size" />
<param name="CountDirection" value="1" />
<param name="MaximumFileSize" value="1MB" />
<param name="MaxSizeRollBackups" value="1024" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
</log4net>
</configuration>
2、初始化:
string logConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log4Net.config");
XmlConfigurator.Configure(new FileStream(logConfigPath, FileMode.Open));
以上是关于log4net配置与初始化的主要内容,如果未能解决你的问题,请参考以下文章