Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-503

RollingFileAppender incorrectly parses rolled over files when determining original backup size

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.2.15
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      Given the following files in the /home/sotirios/ directory

      -rw-r--r-- 1 sotirios users   1075 Jan 26 16:20 debug.log
      -rw-r--r-- 1 sotirios users   2147 Jan 26 12:35 debug.log-20150115
      -rw-r--r-- 1 sotirios users   2147 Jan 26 12:35 debug.log-20150115.1
      -rw-r--r-- 1 sotirios users   2147 Jan 26 12:35 debug.log-20150115.2
      

      and the following sample configuration

      <?xml version="1.0" encoding="utf-8"?>
      <log4net>
        <root>
        </root>
        <logger name="Test">
          <appender-ref ref="LogFileAppender" />
          <level value="DEBUG" />
        </logger>
        
        <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
          <datePattern value="'-'yyyyMMdd" />
          <encoding value="utf-8" />
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%utcdate [%property{THREAD-ID}] %-5level %logger - %message%newline" />
          </layout>
          <maximumFileSize value="1KB" />
          <maxSizeRollBackups value="5" />
          <param name="AppendToFile" value="true" />
          <param name="File" value="/home/sotirios/debug.log" />
          <rollingStyle value="Composite" />
          <staticLogFileName value="true" />
        </appender>
      </log4net>
      

      when log4net is initialized, all the files in the directory above will be passed to InitializeFromOneFile and the m_curSizeRollBackups will be set to 2, even though the current iteration of the base file has no backups. In this case, only the 20150115 rollovers have backups.

      When this RollingFileAppender eventually needs to create a backup, it will attempt to rollover backups 1 and 2 first, which don't exist.

      This is unnecessary and creates misleading WARN logs.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Sotirios Sotirios Delimanolis
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: