View Code
1 1.固定文件存储<configSections> 2 <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/> 3 </configSections> 4 <log4net> 5 <root> 6 <appender-ref ref="LogFileAppender" /> 7 </root> 8 <!--定义输出到文件中--> 9 <appender name="LogFileAppender" type="log4net.Appender.FileAppender"> 10 <file value="c:\log4netfile.txt" /> 11 <appendToFile value="true" /> 12 <rollingStyle value="Date" /> 13 <datePattern value="yyyyMMdd-HH:mm:ss" /> 14 <layout type="log4net.Layout.PatternLayout"> 15 <footer value="by aheak" /> 16 <conversionPattern value="记录时间:%date 线程ID:[%thread] 出错类:%logger property:[%property{NDC}] - 描述:%message%newline" /> 17 </layout> 18 </appender> 19 </log4net>
2.按日期创建文件存储
View Code
1 <log4net> 2 <root> 3 <appender-ref ref="RollingLogFileAppender" /> 4 </root> 5 <appender name="RollingLogFileAppender"type="log4net.Appender.RollingFileAppender"> 6 <!--日志文件名开头--> 7 <param name="File" value="c://" /> 8 <!--是否追加到文件--> 9 <param name="AppendToFile" value="true" /> 10 <param name="MaxSizeRollBackups" value="10" /> 11 <param name="StaticLogFileName" value="false" /> 12 <!--日志文件格式--> 13 <param name="DatePattern" value="yyyyMMdd".log"" /> 14 <!--按照文件的大小进行变换日志文件--> 15 <!--<param name="RollingStyle" value="Size" />--> 16 <!--我这里按照日期--> 17 <param name="RollingStyle" value="Date" /> 18 <layout type="log4net.Layout.PatternLayout"> 19 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n%n" /> 20 </layout> 21 </appender> 22 </log4net>