5.日志详细配置(参考)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net debug="true">
<!--控制台界面日志输出-->
<appender name="ManagedColoredConsoleAppender" type="log4net.Appender.ManagedColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="White" />
<backColor value="Red" />
</mapping>
<mapping>
<level value="WARN" />
<foreColor value="Yellow" />
</mapping>
<mapping>
<level value="INFO" />
<foreColor value="White" />
</mapping>
<mapping>
<level value="DEBUG" />
<foreColor value="Blue" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date] %thread -- %-5level -- %logger [%M] -- %message%newline" />
</layout>
</appender>
<!--本地文件日志记录-->
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/applicationLog.log" />
<!--file可以指定具体的路径 eg : d:\test.log。不指定的话log被生成在项目的bin/Debug 或者 bin/Release目录下 (web的项目 默认生成在根目录下)-->
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<!--备份log文件的个数最多10个-->
<maximumFileSize value="2MB" />
<!--每个log文件最大是2M,如果超过2M将重新创建一个新的log文件,并将原来的log文件备份。-->
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<!--指定log的格式-->
<conversionPattern value="[%date] %thread -- %-5level -- %logger [%M] -- %message%newline" />
</layout>
</appender>
<!--数据库日志记录-->
<appender name="WcsLogDBAppender" type="log4net.Appender.ADONetAppender">
<filter type="com.jt.wcs.common.log.WcsLogFilter,com.jt.wcs.common" />
<bufferSize value="1"/>
<!--设置日志缓冲区大小,设置为最小,这样就可以实时写入数据,否则每次缓冲区必须填满才会写入数据库-->
<param name="ConnectionType" value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" />
<param name="ConnectionString" value="Database=ui;Data Source=localhost;User Id=root;Password=123456;CharSet=utf8;port=3308;SslMode=none;"/>
<param name="CommandText" value="insert into processlog(logtime,source,logger,loglevel,taskkey,lpn,logcontent) values(@log_time, @source, @log_logger, @log_level, @taskkey,@lpn,@log_content)" />
<parameter>
<parameterName value="@log_time"/>
<dbType value="DateTime"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level"/>
<dbType value="String"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%p" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_logger"/>
<dbType value="String"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%c" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_content"/>
<dbType value="String"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%m" />
</layout>
</parameter>
<parameter>
<parameterName value="@source"/>
<dbType value="String"/>
<layout type="com.jt.wcs.common.log.WcsLogLayout,com.jt.wcs.common">
<conversionPattern value="%ec" />
</layout>
</parameter>
<parameter>
<parameterName value="@taskkey"/>
<dbType value="String"/>
<layout type="com.jt.wcs.common.log.WcsLogLayout,com.jt.wcs.common">
<conversionPattern value="%task" />
</layout>
</parameter>
<parameter>
<parameterName value="@lpn"/>
<dbType value="String" />
<layout type="com.jt.wcs.common.log.WcsLogLayout,com.jt.wcs.common">
<conversionPattern value="%lpn" />
</layout>
</parameter>
</appender>
<appender name="asyncForwarder" type="Log4Net.Async.ParallelForwardingAppender,Log4Net.Async">
<appender-ref ref="WcsLogDBAppender" />
<bufferSize value="800" />
</appender>
<root>
<level value="DEBUG" />
<!--指定将此级别及以上的log打印到log文件中-->
<appender-ref ref="ManagedColoredConsoleAppender" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="asyncForwarder" />
</root>
</log4net>
</configuration>