开发者

is it possible to have a new file for each new day with log4cXX

开发者 https://www.devze.com 2023-03-29 12:01 出处:网络
I know the rollingPolicy parameter for log4cxx config file, but I can\'t manage to have the config file which cantell the logger to create a new file eac开发者_如何学Pythonh new day, how could I achie

I know the rollingPolicy parameter for log4cxx config file, but I can't manage to have the config file which can tell the logger to create a new file eac开发者_如何学Pythonh new day, how could I achieve this result ?


Yes. Using rolling style of Composite like this:

   <appender name="LogAppender" type="log4net.Appender.RollingFileAppender">
    <file type="log4j.Util.PatternString" value="LogFile.log" />
    <appendToFile value="true" />
    <rollingStyle value="Composite" />
    <datePattern value="yyyyMMdd" />
    <maxSizeRollBackups value="7" />
    <maximumFileSize value="100MB" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date{ISO8601}: [%2thread] %-5level %logger: '%P{network}.%P{node}' %message%newline" />
    </layout>
    </appender>

Ref.:

Short introduction to Apache log4cxx

log4net Config Examples


I think the following appender will do the stuff ( can't test it on this pc )

    <!-- the following appender with the name "TimeBasedLog.log", every night a few seconds after
     12::00PM the old log will be renamed with append the date in filename, and a new log file
     with the name "TimeBasedLog.log" will be create. 
     notice the RollingFileAppender is under "org.apache.log4j.rolling" namespace
-->
<appender name="MyRollingAppenderDaily" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
        <param name="FileNamePattern" value="TimeBasedLog.%d{yyyy-MM-dd}.log"/>
        <param name="activeFileName" value="TimeBasedLog.log"/>
    </rollingPolicy>

    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] (%F:%L) %m%n"/>
    </layout> 
    <param name="file" value="TimeBasedLog.log"/>
    <param name="append" value="true"/>
</appender>

I am wondering if it is possible to combine inside an appender both timebasedrollingpolicy and MaxFileSize/MaxBackupIndex feature ?

        <param name="MaxFileSize" value="5KB"/>
    <param name="MaxBackupIndex" value="5"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号