You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "sun lixiang (JIRA)" <ji...@apache.org> on 2017/12/10 13:36:06 UTC

[jira] [Updated] (LOG4NET-584) MaxSizeRollBackups can not works

     [ https://issues.apache.org/jira/browse/LOG4NET-584?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

sun lixiang updated LOG4NET-584:
--------------------------------
    Docs Text: 
when set the <PreserveLogFileNameExtension value="true" /> ,the <MaxSizeRollBackups value="2"/> can not works.		

The issus is caused by func. RollingFileAppender:RollOverRenameFiles(string baseFileName) 

and I changed to this.


		protected void RollOverSize() 
		{
			this.CloseFile(); // keep windows happy.
	
			LogLog.Debug(declaringType, "rolling over count ["+((CountingQuietTextWriter)QuietWriter).Count+"]");
			LogLog.Debug(declaringType, "maxSizeRollBackups ["+m_maxSizeRollBackups+"]");
			LogLog.Debug(declaringType, "curSizeRollBackups ["+m_curSizeRollBackups+"]");
			LogLog.Debug(declaringType, "countDirection ["+m_countDirection+"]");

			RollOverRenameFiles(File);
	
			//if (!m_staticLogFileName && m_countDirection >= 0) 
			//{
			//	m_curSizeRollBackups++;
			//}

			// This will also close the file. This is OK since multiple close operations are safe.
			SafeOpenFile(m_baseFileName, false);
		}

protected void RollOverRenameFiles(string baseFileName) 
		{
			// If maxBackups <= 0, then there is no file renaming to be done.
			if (m_maxSizeRollBackups != 0) 
			{
				if (m_countDirection < 0) 
				{
					// Delete the oldest file, to keep Windows happy.
					if (m_curSizeRollBackups == m_maxSizeRollBackups) 
					{
                        DeleteFile(CombinePath(baseFileName, "." + m_maxSizeRollBackups));
						m_curSizeRollBackups--;
					}
	
					// Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
					for (int i = m_curSizeRollBackups; i >= 1; i--) 
					{
                        RollFile((CombinePath(baseFileName, "." + i)), (CombinePath(baseFileName, "." + (i + 1))));
					}
	
					m_curSizeRollBackups++;

					// Rename fileName to fileName.1
                    RollFile(baseFileName, CombinePath(baseFileName, ".1"));
				} 
				else 
				{
					//countDirection >= 0
					if (m_curSizeRollBackups >= m_maxSizeRollBackups && m_maxSizeRollBackups > 0) 
					{
                        m_curSizeRollBackups = 0;
                        ////delete the first and keep counting up.
                        //int oldestFileIndex = m_curSizeRollBackups - m_maxSizeRollBackups;

                        //// If static then there is 1 file without a number, therefore 1 less archive
                        //if (m_staticLogFileName)
                        //{
                        //    oldestFileIndex++;
                        //}

                        //// If using a static log file then the base for the numbered sequence is the baseFileName passed in
                        //// If not using a static log file then the baseFileName will already have a numbered postfix which
                        //// we must remove, however it may have a date postfix which we must keep!
                        //string archiveFileBaseName = baseFileName;
                        //if (!m_staticLogFileName)
                        //{
                        //    int lastDotIndex = archiveFileBaseName.LastIndexOf(".");
                        //    if (lastDotIndex >= 0)
                        //    {
                        //        archiveFileBaseName = archiveFileBaseName.Substring(0, lastDotIndex);
                        //    }
                        //}


                        //// Delete the archive file
                        //DeleteFile(CombinePath(archiveFileBaseName, "." + oldestFileIndex));
                    }
                    else
                    {
                        m_curSizeRollBackups++;
                    }

                    //if (m_staticLogFileName)
                    //{
                    //    m_curSizeRollBackups++;
                    //    RollFile(baseFileName, CombinePath(baseFileName, "." + m_curSizeRollBackups));
                    //}
                }
			}
		}

  was:
		protected void RollOverRenameFiles(string baseFileName) 
		{
			// If maxBackups <= 0, then there is no file renaming to be done.
			if (m_maxSizeRollBackups != 0) 
			{
				if (m_countDirection < 0) 
				{
					// Delete the oldest file, to keep Windows happy.
					if (m_curSizeRollBackups == m_maxSizeRollBackups) 
					{
                        DeleteFile(CombinePath(baseFileName, "." + m_maxSizeRollBackups));
						m_curSizeRollBackups--;
					}
	
					// Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
					for (int i = m_curSizeRollBackups; i >= 1; i--) 
					{
                        RollFile((CombinePath(baseFileName, "." + i)), (CombinePath(baseFileName, "." + (i + 1))));
					}
	
					m_curSizeRollBackups++;

					// Rename fileName to fileName.1
                    RollFile(baseFileName, CombinePath(baseFileName, ".1"));
				} 
				else 
				{
					//countDirection >= 0
					if (m_curSizeRollBackups >= m_maxSizeRollBackups && m_maxSizeRollBackups > 0) 
					{
                        m_curSizeRollBackups = 0;
                        ////delete the first and keep counting up.
                        //int oldestFileIndex = m_curSizeRollBackups - m_maxSizeRollBackups;

                        //// If static then there is 1 file without a number, therefore 1 less archive
                        //if (m_staticLogFileName)
                        //{
                        //    oldestFileIndex++;
                        //}

                        //// If using a static log file then the base for the numbered sequence is the baseFileName passed in
                        //// If not using a static log file then the baseFileName will already have a numbered postfix which
                        //// we must remove, however it may have a date postfix which we must keep!
                        //string archiveFileBaseName = baseFileName;
                        //if (!m_staticLogFileName)
                        //{
                        //    int lastDotIndex = archiveFileBaseName.LastIndexOf(".");
                        //    if (lastDotIndex >= 0)
                        //    {
                        //        archiveFileBaseName = archiveFileBaseName.Substring(0, lastDotIndex);
                        //    }
                        //}


                        //// Delete the archive file
                        //DeleteFile(CombinePath(archiveFileBaseName, "." + oldestFileIndex));
                    }
                    else
                    {
                        m_curSizeRollBackups++;
                    }

                    //if (m_staticLogFileName)
                    //{
                    //    m_curSizeRollBackups++;
                    //    RollFile(baseFileName, CombinePath(baseFileName, "." + m_curSizeRollBackups));
                    //}
                }
			}
		}


> MaxSizeRollBackups can not works
> --------------------------------
>
>                 Key: LOG4NET-584
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-584
>             Project: Log4net
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.0.8
>         Environment: .net 4.5
>            Reporter: sun lixiang
>              Labels: patch
>
> when set the <PreserveLogFileNameExtension value="true" /> ,the <MaxSizeRollBackups value="2"/> can not works.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)