Log4net
  1. Log4net
  2. LOG4NET-60

Bug in RollingFileAppender.cs causing failure to timely roll files on monthly interval

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.9
    • Fix Version/s: 1.2.10
    • Component/s: Appenders
    • Labels:
      None

      Description

      code in said file looks like this

      case RollPoint.TopOfMonth:
      current = current.AddMilliseconds(-current.Millisecond);
      current = current.AddSeconds(-current.Second);
      current = current.AddMinutes(-current.Minute);
      current = current.AddHours(-current.Hour);
      current = current.AddMonths(1);
      break;

      i belive it should look something like this

      case RollPoint.TopOfMonth:
      current = current.AddMilliseconds(-current.Millisecond);
      current = current.AddSeconds(-current.Second);
      current = current.AddMinutes(-current.Minute);
      current = current.AddHours(-current.Hour);
      current = current.AddDays(1 - current.Day); // this line seems to be needed
      current = current.AddMonths(1);
      break;

      also in a separate issue, since there is no RollPoint.TopOfYear, this comment in another part of the code seems wrong:

      //is the new file name equivalent to the 'current' one
      //something has gone wrong if we hit this – we should only
      //roll over if the new file will be different from the old
      string dateFormat = m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo);
      if (m_scheduledFilename.Equals(File + dateFormat))

      { ErrorHandler.Error("Compare " + m_scheduledFilename + " : " + File + dateFormat); return; }

      if the date pattern specifies only the year (rolling yearly), then i think this "error" will be triggered incorrectly 11 times a year. it's fine not to roll, but reporting an error is inappropriate.

        Activity

        Lanchon created issue -
        Nicko Cadell made changes -
        Field Original Value New Value
        Assignee Nicko Cadell [ nicko ]
        Hide
        Nicko Cadell added a comment -

        The first point about the missing AddDays(1 - current.Day) is valid and I will check in a fix for this.

        The second point I don't think is valid because there is not TopOfYear roll point. On its own the year cannot be used as a date pattern. When the date pattern is set to 'yyyy' the appender does not fall back to TopOfMonth but rather generates the following error message in the log4net internal debug log:

        log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [RollingFileAppender] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
        System.ArgumentException: Invalid RollPoint, unable to parse [yyyy]
        at log4net.Appender.RollingFileAppender.ActivateOptions() in C:\work\svn_root\apache\log4net\trunk\src\Appender\RollingFileAppender.cs:line 960

        The appender is not configured or attached to any loggers, therefore the suggested error message would not occur.

        Show
        Nicko Cadell added a comment - The first point about the missing AddDays(1 - current.Day) is valid and I will check in a fix for this. The second point I don't think is valid because there is not TopOfYear roll point. On its own the year cannot be used as a date pattern. When the date pattern is set to 'yyyy' the appender does not fall back to TopOfMonth but rather generates the following error message in the log4net internal debug log: log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [RollingFileAppender] of type [log4net.Appender.RollingFileAppender] . Reported error follows. System.ArgumentException: Invalid RollPoint, unable to parse [yyyy] at log4net.Appender.RollingFileAppender.ActivateOptions() in C:\work\svn_root\apache\log4net\trunk\src\Appender\RollingFileAppender.cs:line 960 The appender is not configured or attached to any loggers, therefore the suggested error message would not occur.
        Hide
        Nicko Cadell added a comment -

        Checked in a fix for the incorrect calculation of the NextCheckDate for the TopOfMonth roll point.

        Show
        Nicko Cadell added a comment - Checked in a fix for the incorrect calculation of the NextCheckDate for the TopOfMonth roll point.
        Nicko Cadell made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.2.10 [ 11128 ]
        Nicko Cadell made changes -
        Summary possible bugs in RollingFileAppender.cs causing failure to timly roll files on monthly or yearly intervals (and inappropriate error reports on yearly intervals). possible bugs in RollingFileAppender.cs causing failure to timely roll files on monthly or yearly intervals (and inappropriate error reports on yearly intervals).
        Nicko Cadell made changes -
        Summary possible bugs in RollingFileAppender.cs causing failure to timely roll files on monthly or yearly intervals (and inappropriate error reports on yearly intervals). Bug in RollingFileAppender.cs causing failure to timely roll files on monthly interval

          People

          • Assignee:
            Nicko Cadell
            Reporter:
            Lanchon
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development