lingFileAppender根据日期和大小使用log4net

lingFileAppender根据日期和大小使用log4net

本文介绍了如何配置RollingFileAppender根据日期和大小使用log4net滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将log4net配置为使用复合RollingFileAppender,以便当前文件始终命名为 logfile.log ,所有后续文件均命名为 logfile-YYYY.MM.dd.seq.log 其中 seq 是日志在一天内超过特定大小的序列号。不幸的是,我在配置这样的设置方面没有成功。



编辑



我的当前配置已粘贴到下面。它已经更新,基于几个答案,让我足够接近我的需要。这会生成以下格式的文件: logfile_YYYY.MM.dd.log.seq

 < log4net> ; 

< root>
< level value =DEBUG/>
< appender-ref ref =RollingFileAppender/>
< / root>

< appender name =RollingFileAppendertype =log4net.Appender.RollingFileAppender>
< file value =logs\\logfile/>
< staticLogFileName value =false/>
< appendToFile value =true/>
< rollingStyle value =Composite/>
< datePattern value =_ yyyy.MM.dd& quot; .log& quot;/>
< maxSizeRollBackups value =10/>
< maximumFileSize value =75KB/>
< layout type =log4net.Layout.PatternLayout>
< conversionPattern value =%date [%thread]%-5级别%logger [%property {NDC}] - %message%newline/>
< / layout>
< filter type =log4net.Filter.LevelRangeFilter>
< param name =LevelMinvalue =DEBUG/>
< param name =LevelMaxvalue =FATAL/>
< / filter>
< / appender>

< / log4net>

一个有趣的注释,设置

 < staticLogFileName value =false/> 

为true将使记录器不写入任何文件。

解决方案

我们使用以下(在Log4J中):

  appender name =rollerclass =org.apache.log4j.DailyRollingFileAppender> 
< param name =Filevalue =Applog.log/>
< param name =DatePatternvalue ='。'yyyy-MM-dd/>
< layout class =org.apache.log4j.PatternLayout>
< param name =ConversionPatternvalue =[slf5s.start]%d {DATE} [slf5s.DATE]%n%p [slf5s.PRIORITY]%n%x [slf5s.NDC]%n %t [slf5s.THREAD]%n%c [slf5s.CATEGORY]%n%l [slf5s.LOCATION]%n%m [slf5s.MESSAGE]%n%n/>
< / layout>
< / appender>

这会给我们 Applog.log.yyyy-MM-dd / p>

I am configure log4net to use a composite RollingFileAppender so that the current file is always named logfile.log and all subsequent files are named logfile-YYYY.MM.dd.seq.log where seq is the sequence number if a log exceeds a certain size within a single day. Unfortunately, I have had very little success in configuring such a setup.

Edit:

My current configuration is pasted below. It has been updated based on several answers which gets me close enough for my needs. This generates files of the format: logfile_YYYY.MM.dd.log.seq

<log4net>

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

    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="logs\\logfile"/>
        <staticLogFileName value="false"/>
        <appendToFile value="true"/>
        <rollingStyle value="Composite"/>
        <datePattern value="_yyyy.MM.dd&quot;.log&quot;"/>
        <maxSizeRollBackups value="10"/>
        <maximumFileSize value="75KB"/>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
        </layout>
        <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG" />
            <param name="LevelMax" value="FATAL" />
        </filter>
    </appender>

</log4net>

One interesting note, setting

<staticLogFileName value="false"/>

to true causes the logger to not write any files.

解决方案

We use the following (in Log4J):

<appender name="roller" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="Applog.log"/>
    <param name="DatePattern" value="'.'yyyy-MM-dd"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="[slf5s.start]%d{DATE}[slf5s.DATE]%n%p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n%c[slf5s.CATEGORY]%n%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n"/>
    </layout>
</appender>

This gives us Applog.log.yyyy-MM-dd files

这篇关于如何配置RollingFileAppender根据日期和大小使用log4net滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:42