[ https://issues.apache.org/jira/browse/LOG4NET-27?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13554863#comment-13554863 ]
Spamme commented on LOG4NET-27: ------------------------------- Yes, it is expecting that you have exactly 1 log file per each possible changing, I know is not a perfect solution. The better approach would be to save all the file names in a another file, when you create a new file you add it to the list and you pop the old ones and delete them. You have only to find an unique name for the history file, for example LoggerName.history.txt. This is also an imperfect solution, because if somebody deletes the history file ... you can't delete the old files anymore. But at the end there isn't a perfect solution, you have always to chose what fits at best your needs. This solution is safe against any change in the configuration, if you want you could set the history file hidden, so it would be more difficult for a normal user to delete it, or you could also open it and lock it, so nobody can change or delete it as long as the application is running, but personally I don't like this method. protected void RollOverTime(bool fileIsOpen) { ... //Delete old files if (m_maxSizeRollBackups != 0) { //Opening the history file using (FileStream fs = new FileStream(Name + ".history.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { try { //Reading the content of the file and transform it to a list var list = new List<string>((new StreamReader(fs).ReadToEnd()).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); //Adding the new file name list.Add(dateFormat); //While the list is longer than the max length while (list.Count > m_maxSizeRollBackups) { //Getting the first file name in the list var oldFile = CombinePath(File, list[0]); //Deleting the first file name if it exists if (FileExists(oldFile)) DeleteFile(oldFile); //Removing the first file name list.RemoveAt(0); } //Repositioning the stream to the begin fs.Position = 0; //Write the new list to the file new StreamWriter(fs) { AutoFlush = true }.Write(string.Join(";", list)); //Clearing the rest of the stream fs.SetLength(fs.Position); } //Closing the file finally { fs.Close(); } } } .... } > 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