You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Akhil Bandari (Jira)" <ji...@apache.org> on 2021/07/27 14:03:00 UTC

[jira] [Created] (LOG4NET-672) Previous rolled files not taken into consideration after restart the Logging Manager with a specific date-pattern

Akhil Bandari created LOG4NET-672:
-------------------------------------

             Summary: Previous rolled files not taken into consideration after restart the Logging Manager with a specific date-pattern 
                 Key: LOG4NET-672
                 URL: https://issues.apache.org/jira/browse/LOG4NET-672
             Project: Log4net
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 2.0.10
            Reporter: Akhil Bandari


{code:xml}
<log4net>		
<appender name="LogFileAppenderXML" type="log4net.Appender.RollingFileAppender">			<file value="Logs\.xml" />			
<datePattern value="yyyy-MM-dd-'Xyz'" />			
<appendToFile value="true" />			
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />			<rollingStyle value="Composite" />			
<maxSizeRollBackups value="40" />			
<maximumFileSize value="1MB" />			
<preserveLogFileNameExtension value="true" />			
<staticLogFileName value="true" />			
<layout type="log4net.Layout.XmlLayout"/>		
</appender>		
<root>			
<level value="ALL"/>			
<appender-ref ref="LogFileAppenderXML"></appender-ref>		
</root>	
</log4net>                             
{code}
 

With the above configuration, the rolling was working fine for a single run of the application, but after a restart of the logging manager (or the application), the previous rolled files are overwritten instead of new rolled files being created with the last highest rolled file index. 

+*Steps to reproduce:*+
 # Create an application [console or wpf]  with the above log4net config
 # Start logging
 ## Until At least 10 rolled files are created
 # Close and ReStart the application
 # Start logging again
 ##  Observe the rolled files
 ##  Start logging and when the logging information reaches to maximumFileSize, {color:#172b4d}the previous rolled file content will be overwritten with new content, _*instead of increasing the rolled file count.*_{color}

{color:#172b4d}Looked into the source code of *RollingFileAppender* found that {color}
 * {color:#172b4d}At the initial phase all the rolled file names, are converted into the *LowerInvariant and* passing to the *InitializeFromOneFile* method{color}

 
{code:c#}
private void InitializeRollBackups(string baseFile, ArrayList arrayFiles)
{
	if (null != arrayFiles)
	{
	     string baseFileLower = baseFile.ToLowerInvariant();
	     foreach(string curFileName in arrayFiles)
	     {
		  InitializeFromOneFile(baseFileLower,curFileName.ToLowerInvariant());
	     }
        }
}
{code}
 - Inside *InitializeFromOneFile*

      - The date variable is not converting to lower or while comparing the *curFileName with a prefix not using ignoreCase*

      - that is leading not to get last rolled file index
{code:c#}
if (!curFileName.StartsWith(prefix) || !curFileName.EndsWith(suffix))
{ 
       LogLog.Debug(declaringType, "Ignoring file ["+curFileName+"] 
       because it is from a different date period");
      return; 
}            
{code}
Is there any possibility to use ignoreCase while comparing curFileName with the prefix
{code:c#}
 if (!curFileName.StartsWith(prefix,true,CultureInfo.InvariantCulture) || !curFileName.EndsWith(suffix))
{code}
 

 Or is there any reason not to _*use ignoreCase while comparing curFileName*_ with the _*prefix?*_

 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)