Rolling File Appender使用示例

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--In a config file where there will (potentially) be more information stored
beyond just the log4net configuration information,
you will need to specify a section to identify where the log4net configuration is housed.-->
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net-net-1.0"/>
</configSections>

<log4net>
<root>
<level value="INFO" />
<appender-ref ref="RollingFileAppender" />
</root>

<!--Note that the logger name is the full name of the class including the namespace.
If you wanted to monitor an entire namespace,
it would be as simple as listing just the namespace you wanted to monitor.
I would recommend against trying to re-use appenders in multiple loggers.
It can be done, but you can get some unpredictable results.-->
<logger name="ModemApplication.Logging">
<level value="DEBUG"/>
</logger>

<!--the log file should be capped at 10MB and keep up to 5 archive files
before start deleting them (oldest gets deleted first).
The archives will be named with the same name as the file,
only with a dot and the number after it.-->
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender" >
<param name="File" value="GetMessage-logfile.txt" />
<param name="AppendToFile" value="true" />
<param name="rollingStyle" valye="Size" />
<param name="maxSizeRollBackups" value="5" />
<param name="maximumFileSize" value="1MB" />
<param name="staticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern"
value="%date [%thread] %-5level %c - %message %exception%n"
/>
</layout>
<!--When a message fits inside the criteria for a filter,
it is logged and the processing of the filter is finished.-->
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="FATAL" />
</filter>
<!--its true purpose is to specify that nothing more should be logged -->
<filter type="log4net.Filter.DenyAllFilter" />
</appender>

</log4net>
</configuration>


 

原文地址:https://www.cnblogs.com/ttssrs/p/2431273.html