void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Sxmobi.FileHelper.GetMapPath("~\\log4net.config")));
}
2. log4net.config 文件
<!--注意logger节点至少有1个-->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net debug="false">
<!--配置日志记录相关参数-->
<!--按日期生成日志文件-->
<appender name="DebugLogger" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="30"/>
<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="%n[Header]%n%d [%t] %-5p %c [%x] [%X{auth}]%n - %m%n[Footer]%n"/>
</layout>
</appender>
<!--按指定大小生成日志文件-->
<logger name="Memcached" additivity="false">
<level value="ALL" />
<appender-ref ref="Memcached" />
</logger>
<appender name="Memcached" type="log4net.Appender.RollingFileAppender">
<param name="File" value="log/Memcache/Memcached.txt"/>
<param name="MaxSizeRollBackups" value="10"/>
<!-- 切割最多文件数 -->
<param name="MaximumFileSize" value="10240KB"/>
<!-- 每个文件的大小 -->
<param name="AppendToFile" value="true"/>
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<!-- 如要使用不同的日志文件,在上面添加一个Appender节点并设置File值,
然后在下面添加一个logger节点即可-->
<root>
<!--(高) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (低) -->
<level value="DEBUG"/>
<appender-ref ref="DebugLogger"/>
</root>
</log4net>
</configuration>
log4net下载地址:https://files.cnblogs.com/dashi/log4net.rar