[ 
https://issues.apache.org/jira/browse/LOG4NET-27?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13553625#comment-13553625
 ] 

Spamme commented on LOG4NET-27:
-------------------------------

Hello, I find really funny, that this issue has been open 8 years ago and there 
isn't a solution for it yet. So I don't want to do all the job, I can give you 
some code and perhaps you can improve and test it. (Why? Because I have only 
take a look to the RollingFileAppender.cs code and I didn't checked out the 
whole source)


protected void RollOverTime(bool fileIsOpen)
{
    ....
    //Delete old file
    if (m_maxSizeRollBackups != 0)
    {
        //Possible intervals for the date format changing: 1 sec, 1 min, 1 
hours, 1 day, 1 week, 1 month, 1 year (this could be also a constant)
        //Note: using 31 days for the month and 366 days (leap year) for the 
year, 
        //shouldn't be a problem because the function is called when the log 
file name has already changed
        var intervals = new double[] { 1, 60, 60 * 60, 60 * 60 * 24, 60 * 60 * 
24 * 7, 60 * 60 * 24 * 31, 60 * 60 * 24 * 366 };

        foreach (var interval in intervals) 
        {
            //Traveling back in time, weeeee.....
            var oldDate = m_now.AddSeconds(-interval);
            var oldDateFormat = oldDate.ToString(m_datePattern, 
System.Globalization.DateTimeFormatInfo.InvariantInfo);

            if (oldDateFormat != dateFormat)
            {
                //Bingo, date format changed, we have found the minimal 
interval for date format changing
                //Now calculate the the date format back m_maxSizeRollBackups 
times, time traveling again, weeeeee.....
                oldDate = m_now.AddSeconds(-interval * m_maxSizeRollBackups);
                oldDateFormat = oldDate.ToString(m_datePattern, 
System.Globalization.DateTimeFormatInfo.InvariantInfo);

                //Create the old file name and checking if exists, if exists 
delete it
                var oldFileName = CombinePath(File, oldDateFormat);
                if (FileExists(oldFileName)) DeleteFile(oldFileName);

                //we are done, break it
                break;
            }
        }
    }
    ...
}
                
> Rolling files on date/time boundaries doesn't support a maximum number of 
> backup files.
> ---------------------------------------------------------------------------------------
>
>                 Key: LOG4NET-27
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-27
>             Project: Log4net
>          Issue Type: New Feature
>          Components: Appenders
>    Affects Versions: 1.2.11
>            Reporter: Florian Ramillien
>            Priority: Minor
>             Fix For: 1.2 Maintenance Release
>
>         Attachments: LOG4NET-27.patch, RollingFileAppender.cs, 
> RollingFileAppender.cs, RollingFileAppender.cs, RollingFileAppender.cs.patch, 
> RollingFileAppender.patch
>
>
> A maximum of backup files exist when rolling files on file size, but not for 
> rolling on date/time.
> This can be implemented with the same config key : MaxSizeRollBackups

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to