Log4net使用(二)
转:http://www.cnblogs.com/basilwang/archive/2006/06/09/421868.html
Log4net同时按照日期和大小生成RollingFile和访问Sybase数据库配置
1. Log4net同时按照日期和大小生成RollingFile
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="test.log" /> <appendToFile value="true" /> <rollingStyle value="Composite" /> <datePattern value=".yyyy_MM_dd" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10000" /> <staticLogFileName value="false" /> <layout type="log4net.Layout.PatternLayout"> <header value="[Header] " /> <footer value="[Footer] " /> <conversionPattern value="%date %type %file %line %method %location %class %C %F %L %l %M" /> </layout> </appender> 这样生成的日志类似test.log.2006_06_09,test.log.2006_06_08,如果哪一天的日志超过10000,那么日志名为test.log.2006_06_10.1、test.log.2006_06_10.2 .......
2.访问Sybase数据库配置
<appender name="ADONetAppender_Sybase1" type="log4net.Appender.AdoNetAppender"> <bufferSize value="1" /> <connectionType value="System.Data.Odbc.OdbcConnection, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <connectionString value="Driver={SYBASE SYSTEM 11};Srvr=basil;Uid=sa;Pwd=;DB=AddressBook" /> <commandText value="Log_add ? ,? , ?, ?, ?" /> <commandType value="StoredProcedure" /> <parameter> <parameterName value="@log_date" /> <dbType value="DateTime" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-dd hh:mm:ss}" /> </layout> </parameter> <parameter> <parameterName value="@thread" /> <dbType value="String" /> <size value="255" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%thread -just for test" /> </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="255" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%message" /> </layout> </parameter> </appender>