Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arie 224 posts 675 karma points
    Feb 06, 2013 @ 01:38
    Arie
    0

    log4net - how to limit number of log files / size?

    I've got the following config, but neither the number of files nor the size seems to be limited. There are a number of files that exceed 5MB (one is 127MB!) and the number of files just keeps increasing.

       <appender name="AsynchronousLog4NetAppender" type="Umbraco.Core.Logging.AsynchronousRollingFileAppender, Umbraco.Core">
    <file value="App_Data\Logs\UmbracoTraceLog.txt" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <maximumFileSize value="5MB" />
    <maxSizeRollBackups value="14" />
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
    </layout>
    </appender>

     

  • Arie 224 posts 675 karma points
    Aug 08, 2013 @ 17:04
    Arie
    100

    Adding the following in the <root> node seems to do the trick:

        <priority value="WARN" />

    The log level order is:

    DEBUG

    INFO

    WARN

    ERROR

    FATAL

    Setting the value to "WARN" will log WARN, ERROR, and FATAL.

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Aug 08, 2013 @ 20:31
    Kevin Jump
    0

    the log4net config in umbraco is actually configured to roll over based on date not size. so the logfile will grow and grow until the date changes.

    setting log WARN will certainly make the file smaller however if you want to ensure file sizes are kept to a specific size, set the rollingStyle to either Size or Composite (Date and Size)

    <rollingStyle value="Composite" />
    

    just setting this and logging will just wipe the file when it reaches a size and start again. if you want to keep a history for logging then also set number of backups to keep

    <maxSizeRollBackups value="10" />
    

    This will keep 5 backups everytime the file rolls over (by default umbracotracelog.txt.1, 2, etc)

    so the following will stop the log growing past 5MB and keep only 5 versions (so it should never go past 30MB for logging)

    <appender name="AsynchronousLog4NetAppender" type="Umbraco.Core.Logging.AsynchronousRollingFileAppender, Umbraco.Core">
          <file value="App_Data\Logs\UmbracoTraceLog.txt" />
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
          <appendToFile value="true" />
          <rollingStyle value="Composite" />
          <maximumFileSize value="5MB" />
          <maxSizeRollBackups value="5" />
          <layout type="log4net.Layout.PatternLayout">
             <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
          </layout>
    </appender>
    
Please Sign in or register to post replies

Write your reply to:

Draft