Hello,

This is the first time I contribute to an open source project, your assistance will be much appreciated. I read your FAQ and I believe I'm doing things in the right manner. Please let me know otherwise.

While using version 1.2.13, I'm experiencing the issue described in this bug:
https://issues.apache.org/jira/browse/LOG4NET-378

In a nutshell: My app is running, rolling style is set to Composite, log files are piling up in the folder, all is good. Then I reset IIS, and restart my app. I would expect the rolling to continue on or after the last file. But instead, the rolling restarts at index 1 and overwrites the existing files.

The original bug fix addresses the issue in the *InitializeFromOneFile*() method. However, the *GetWildcardPatternForFile*() method also needs the baseFileName to be adjusted with the datePattern so the proper files are searched. I placed a file path fix in the *DetermineCurSizeRollBackups*() method, so it's then passed down to the two other methods and everyone gets happy.

Here's a calling stack sample:
*DetermineCurSizeRollBackups*()
|
+--GetExistingFiles()
|  +--*GetWildcardPatternForFile*()
|
+--InitializeRollBackups()
   +--*InitializeFromOneFile*()


You'll find attached to this email:
- the part of my web.config file that relates to log4net
- a patch containing my fix

Please let me know how good this fix is, and if it fits your quality standards. Once we're settled, I could work on the unit tests, or let you deal with it at your convenience.

Thanks!

--

*Michel Émond*
Programmer Analyst

Innobec <http://www.innobec.com>

*T*  1-514-272-0979 *#240*
*T* 1-800-972-0979 *#240*
www.innobec.com <http://www.innobec.com>

<log4net>
	<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
		<File value="c:\mylogs\log..txt" />
		<AppendToFile value="true" />
		<MaxSizeRollBackups value="-1" />
		<MaximumFileSize value="5KB" />
		<RollingStyle value="Composite" />
		<PreserveLogFileNameExtension value="true" />
		<DatePattern value="yyyyMMdd" />
		<StaticLogFileName value="false" />
		<CountDirection value="1" />
		<Layout type="log4net.Layout.PatternLayout">
			<header value="%date ======================= LOG START =======================&#xD;&#xA;" type="log4net.Util.PatternString" />
			<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
			<footer value="%date ======================= LOG STOP  =======================&#xD;&#xA;" type="log4net.Util.PatternString" />
		</Layout>
		<Filter type="log4net.Filter.LevelRangeFilter">
			<levelMin value="INFO" />
			<levelMax value="FATAL" />
		</Filter>
	</appender>

	<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
		<param name="LogName" value="synchroservice" />
		<param name="ApplicationName" value="synchroservice" />
		<layout type="log4net.Layout.PatternLayout">
			<conversionPattern value="%utcdate %newline %type %newline %method %newline %message %newline %exception" />
		</layout>
		<filter type="log4net.Filter.LevelRangeFilter">
			<levelMin value="FATAL" />
			<levelMax value="FATAL" />
		</filter>
	</appender>

	<root>
		<level value="DEBUG" />
		<appender-ref ref="RollingLogFileAppender" />
		<appender-ref ref="EventLogAppender" />
	</root>
</log4net>

--- log4net-1.2.13\src\Appender\RollingFileAppender.cs Sun Nov 17 14:44:38 
2013 UTC
+++ log4net-1.2.13-fix\src\Appender\RollingFileAppender.cs      Tue May 12 
17:53:22 2015 UTC
@@ -718,6 +718,10 @@
                        using(SecurityContext.Impersonate(this))
                        {
                                fullPath = 
System.IO.Path.GetFullPath(m_baseFileName);
+                               if (m_rollDate && !m_staticLogFileName)
+                               {
+                                       fullPath = CombinePath(fullPath, 
m_now.ToString(m_datePattern, 
System.Globalization.DateTimeFormatInfo.InvariantInfo));
+                               }
                                fileName = System.IO.Path.GetFileName(fullPath);
                        }
 
@@ -901,19 +905,6 @@
                        }
             */
        
-                       // Only look for files in the current roll point
-                       if (m_rollDate && !m_staticLogFileName)
-                       {
-                               string date = 
m_dateTime.Now.ToString(m_datePattern, 
System.Globalization.DateTimeFormatInfo.InvariantInfo);
-                               string prefix = m_preserveLogFileNameExtension 
? Path.GetFileNameWithoutExtension(baseFile) + date : baseFile + date;
-                               string suffix = m_preserveLogFileNameExtension 
? Path.GetExtension(baseFile) : "";
-                               if (!curFileName.StartsWith(prefix) || 
!curFileName.EndsWith(suffix))
-                               {
-                                       LogLog.Debug(declaringType, "Ignoring 
file ["+curFileName+"] because it is from a different date period");
-                                       return;
-                               }
-                       }
-            
                        try 
                        {
                                // Bump the counter up to the highest count 
seen so far

Reply via email to