Commits

Dominik P committed 1c420d1

Added unique check to cron rolling strategy

Comments (0)

Files changed (1)

 
 diff -r 5a5078efc63a src/Appender/RollingFileAppenderNG.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/RollingFileAppenderNG.cs	Wed Sep 21 22:36:54 2011 +0200
++++ b/src/Appender/RollingFileAppenderNG.cs	Wed Sep 21 22:45:24 2011 +0200
 @@ -0,0 +1,143 @@
 +#region Apache License
 +//
 +}
 diff -r 5a5078efc63a src/Appender/RollingFileAppenderNGAPI/CronRollingCondition.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/RollingFileAppenderNGAPI/CronRollingCondition.cs	Wed Sep 21 22:36:54 2011 +0200
-@@ -0,0 +1,177 @@
++++ b/src/Appender/RollingFileAppenderNGAPI/CronRollingCondition.cs	Wed Sep 21 22:45:24 2011 +0200
+@@ -0,0 +1,198 @@
 +#region Apache License
 +//
 +// Licensed to the Apache Software Foundation (ASF) under one or more 
 +
 +		#endregion
 +
++		#region Private Instance Properties
++
++		private ulong last_rolled = 0;
++
++		#endregion
++
 +		#region Protected Inner Classes
 +
 +		protected enum MatchType
 +		public bool IsMet(string file)
 +		{
 +			DateTime now = DateTime.Now;
++
++			// check only every minute
++			// we can skip the check as we checked this minute already 
++			// and if we don't we may run into the situation to roll a file twice
++			if (GetUniqueIndex(now) == last_rolled)
++			{
++				return false;
++			}
 +			if (!IsMet(Dow, now))
 +			{
 +				return false;
 +			{
 +				return false;
 +			}
++
++			last_rolled = GetUniqueIndex(now);
 +			return true;
 +		}
 +
++		private static uint GetUniqueIndex(DateTime now)
++		{
++			return (uint)now.DayOfWeek * (uint)now.Month * (uint)now.Day * (uint)now.Hour * (uint)now.Minute;
++		}
++
 +		#endregion
 +
 +		#region Private Methods
 +}
 diff -r 5a5078efc63a src/Appender/RollingFileAppenderNGAPI/IRollingCondition.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/RollingFileAppenderNGAPI/IRollingCondition.cs	Wed Sep 21 22:36:54 2011 +0200
++++ b/src/Appender/RollingFileAppenderNGAPI/IRollingCondition.cs	Wed Sep 21 22:45:24 2011 +0200
 @@ -0,0 +1,38 @@
 +#region Apache License
 +//
 +}
 diff -r 5a5078efc63a src/Appender/RollingFileAppenderNGAPI/IRollingStrategy.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/RollingFileAppenderNGAPI/IRollingStrategy.cs	Wed Sep 21 22:36:54 2011 +0200
++++ b/src/Appender/RollingFileAppenderNGAPI/IRollingStrategy.cs	Wed Sep 21 22:45:24 2011 +0200
 @@ -0,0 +1,32 @@
 +#region Apache License
 +//
 +}
 diff -r 5a5078efc63a src/Appender/RollingFileAppenderNGAPI/IndexRollingStrategy.cs
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/src/Appender/RollingFileAppenderNGAPI/IndexRollingStrategy.cs	Wed Sep 21 22:36:54 2011 +0200
++++ b/src/Appender/RollingFileAppenderNGAPI/IndexRollingStrategy.cs	Wed Sep 21 22:45:24 2011 +0200
 @@ -0,0 +1,77 @@
 +#region Apache License
 +//
 +}
 diff -r 5a5078efc63a src/log4net.vs2010.csproj
 --- a/src/log4net.vs2010.csproj	Tue Sep 20 17:52:26 2011 +0000
-+++ b/src/log4net.vs2010.csproj	Wed Sep 21 22:36:54 2011 +0200
++++ b/src/log4net.vs2010.csproj	Wed Sep 21 22:45:24 2011 +0200
 @@ -187,6 +187,13 @@
      <Compile Include="Appender\RollingFileAppender.cs">
        <SubType>Code</SubType>