You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Dominik Psenner (JIRA)" <ji...@apache.org> on 2015/06/23 08:18:00 UTC

[jira] [Comment Edited] (LOG4NET-465) Rolling log files get overwritten when IIS is restarted

    [ https://issues.apache.org/jira/browse/LOG4NET-465?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14597235#comment-14597235 ] 

Dominik Psenner edited comment on LOG4NET-465 at 6/23/15 6:17 AM:
------------------------------------------------------------------

Hi Michel,

thanks for this nice bug report. Haven't seen such a complete one in a long time. You've really put some effort in, didn' you? :-) I just now read your patch, to me this makes sense:

{code}
--- 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);
 			}
{code}

but you gotta explain me why you had to remove these lines:

{code} 
--- 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
@@ -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
{code}

Please don't think I'm nitpicky, I just wanna make sure we do not break existing functionality.

Cheers


was (Author: nachbarslumpi):
Hi Michel,

thanks for this nice bug report. Haven't seen such a complete one in a long time. You've really put some effort in, didn' you? :-) I just now read your patch, to me this makes sense:

{code}
--- 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);
 			}
{code}

but you gotta explain me why you had to remove these lines:

{code} 
@@ -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
{code}

Please don't think I'm nitpicky, I just wanna make sure we do not break existing functionality.

Cheers

> Rolling log files get overwritten when IIS is restarted
> -------------------------------------------------------
>
>                 Key: LOG4NET-465
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-465
>             Project: Log4net
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 1.2.13
>         Environment: asp.net 4.0
>            Reporter: Michel Emond
>         Attachments: RollingFileAppender.diff, config.xml
>
>
> This is the issue described in LOG4NET-378
> h2. Reproduction steps
> # Setup a web application using the settings from the attached config.xml file
> # Notice the rolling style set to Composite
> # Start and use the application
> # The log files pile up in the folder
> # Restart IIS
> # Keep using the application
> Expected result
> - The rolling continues on or after the last file
> Actual result
> - The rolling restarts at index 1 and overwrites the existing files
> h2. Solution
> See the attached files:
> - config.xml
> - patch with a fix proposal
> 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:
> {code}
> DetermineCurSizeRollBackups()
> |
> +--GetExistingFiles()
> |  +--GetWildcardPatternForFile()
> |
> +--InitializeRollBackups()
>    +--InitializeFromOneFile()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)