<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/> </configSections> <log4net> <!--定义输出到文件中--> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > <file value="Logs/" /> <AppendToFile value="true" /> <RollingStyle value="Date" /> <DatePattern value="yyyyMMdd".log""/> <StaticLogFileName value="false" /> <layout type="log4net.Layout.PatternLayout"> <ConversionPattern value="时间:%date 线程:[%thread] 级别:%-5level 类型:%logger property:[%property{NDC}] 描述:%message 异常:%exception%newline" /> </layout> </appender> <!--定义输出到数据库中--> <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender"> <!--缓存,调试时设置为1,上线后应修改。下面的Version为软件版本,需要根据下载的软件进行相应修改--> <bufferSize value="1"/> <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.2.13.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> <connectionString value="data source=.sqlexpress;initial catalog=LeaveWordBorad;integrated security=false;persist security info=True;user id=sa;password=vlj305000"/> <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)"/> <parameter> <parameterName value="@log_date"/> <dbType value="DateTime"/> <layout type="log4net.Layout.RawTimeStampLayout"/> </parameter> <parameter> <parameterName value="@thread"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%thread"/> </layout> </parameter> <parameter> <parameterName value="@log_level"/> <dbType value="String"/> <size value="50"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%level"/> </layout> </parameter> <parameter> <parameterName value="@logger"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%logger"/> </layout> </parameter> <parameter> <parameterName value="@message"/> <dbType value="String"/> <size value="4000"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%message"/> </layout> </parameter> <parameter> <parameterName value="@exception"/> <dbType value="String"/> <size value="2000"/> <layout type="log4net.Layout.ExceptionLayout"/> </parameter> </appender> <!--定义日志的输出媒介,下面定义日志以四种方式输出。也可以下面的按照一种类型或其他类型输出。--> <root> <level value="All" /> <!--文件形式记录日志--> <appender-ref ref="LogFileAppender" /> <appender-ref ref="ADONetAppender" /> </root> </log4net> </configuration>