Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-672

Previous rolled files not taken into consideration after restart the Logging Manager with a specific date-pattern

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.0.10
    • None
    • Appenders
    • None

    Description

      <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>                             
      

       

      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:

      1. Create an application [console or wpf] with the above log4net config
      2. Start logging
        1. Until At least 10 rolled files are created
      3. Close and ReStart the application
      4. Start logging again
        1.  Observe the rolled files
        2.  Start logging and when the logging information reaches to maximumFileSize, the previous rolled file content will be overwritten with new content, instead of increasing the rolled file count.

      Looked into the source code of RollingFileAppender found that 

      • At the initial phase all the rolled file names, are converted into the LowerInvariant and passing to the InitializeFromOneFile method

       

      private void InitializeRollBackups(string baseFile, ArrayList arrayFiles)
      {
      	if (null != arrayFiles)
      	{
      	     string baseFileLower = baseFile.ToLowerInvariant();
      	     foreach(string curFileName in arrayFiles)
      	     {
      		  InitializeFromOneFile(baseFileLower,curFileName.ToLowerInvariant());
      	     }
              }
      }
      

       - 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

      if (!curFileName.StartsWith(prefix) || !curFileName.EndsWith(suffix))
      { 
             LogLog.Debug(declaringType, "Ignoring file ["+curFileName+"] 
             because it is from a different date period");
            return; 
      }            
      

      Is there any possibility to use ignoreCase while comparing curFileName with the prefix

       if (!curFileName.StartsWith(prefix,true,CultureInfo.InvariantCulture) || !curFileName.EndsWith(suffix))
      

       

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

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            AkhilB402 Akhil Bandari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: