C# log4net

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!-- This section contains the log4net configuration settings -->
  <log4net>

    <!-- Setup the root category, add the appenders and set the default level -->
    <!--控制级别,由低到高:ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF-->
    <root>
      <level value="ALL" />
      <appender-ref ref="RollingLogFileAppender" />
    </root>

    <appender name="RollingLogFileAppender " of the type = " log4net.Appender.RollingFileAppender " > 
      <-! Minimum lock model to allow multiple processes can write to the same file -> 
      <lockingModel of the type = " log4net.Appender.FileAppender + MinimalLock " /> 
      <! - log file path -> 
      <file value = " log // " /> 
      <-! whether to append log file -> 
      <appendToFile value = " to true " /> 
      <-! log rolling by date -> 
      <rollingStyle value = " a Date " /> 
      <-! log file name is to be fixed ->
      <staticLogFileName value="false " /> 
      ! <- log file name format is: 2008 - 08 - 31 .log -> 
      <datePattern value = " yyyy-MM-dd'.log ' " /> 
      <- the number of days to retain log -! > 
      <maxSizeRollBackups value = " 10 " /> 
      <-! maximum file size -> 
      <maximumFileSize value = " 1MB " /> 
      <-! information log layout -> 
      <layout of the type = " log4net.Layout.PatternLayout " > 
        <ConversionPattern value = "%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>

  </log4net>
</configuration>
log4net.config

 

initialization

            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo( "C:\\log4net.config"));

Instantiate an object

        static readonly ILog log = LogManager.GetLogger(typeof(MainService));

 

Guess you like

Origin www.cnblogs.com/su-king/p/12554116.html