1

我有以下 log4Net 的配置部分。我想让 log4Net 每月记录文件而不是日期。请求您的帮助...

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender,log4net">
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
  <param name="StaticLogFileName" value="true"/>
  <file type="log4net.Util.PatternString" value="C:\logger\TestLog.log" />
  <appendToFile value="true" />
  <maximumFileSize value="1000KB" />
  <maxSizeRollBackups value="3" />   
  <layout type="log4net.Layout.PatternLayout">
     <conversionPattern value="%level %date{dd MMM yyyy HH:mm:ss,fff} %logger - %message%newline" />
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="INFO" />
    <levelMax value="FATAL" />
  </filter>      
  <filter type="log4net.Filter.DenyAllFilter" />
  <filter type="log4net.Filter.LevelMatchFilter">
    <levelToMatch value="DEBUG" />
  </filter>
</appender>
4

1 回答 1

4

使用以下解决方案修复了问题...

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender,log4net">      
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> 
    <param name="StaticLogFileName" value="true"/> 
    <file type="log4net.Util.PatternString" value="C:\log4net\TestLog_%date{yyyyMM}.log" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <datePattern value="yyyyMM" />
    <maximumFileSize value="1000KB" />
    <maxSizeRollBackups value="3" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%level %date{dd MMM yyyy HH:mm:ss,fff} %logger - %message%newline" />
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO" />
        <levelMax value="FATAL" />
    </filter>
    <filter type="log4net.Filter.DenyAllFilter" />
    <filter type="log4net.Filter.LevelMatchFilter">
        <levelToMatch value="DEBUG" />
     </filter>
</appender>
于 2012-07-17T06:52:45.017 回答