1. Dominik P
  2. log4net-patches

Commits

Dominik P  committed aa28205

Fixed format of the cron rolling condition and fixed the code of the index rolling strategy

  • Participants
  • Parent commits 6f36a5b
  • Branches default

Comments (0)

Files changed (1)

File RFA-NG

View file
 
 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:21:34 2011 +0200
++++ b/src/Appender/RollingFileAppenderNG.cs	Wed Sep 21 22:30:16 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:21:34 2011 +0200
-@@ -0,0 +1,153 @@
++++ b/src/Appender/RollingFileAppenderNGAPI/CronRollingCondition.cs	Wed Sep 21 22:30:16 2011 +0200
+@@ -0,0 +1,177 @@
 +#region Apache License
 +//
 +// Licensed to the Apache Software Foundation (ASF) under one or more 
 +	/// <author>Dominik Psenner</author>
 +	public class CronRollingCondition : IRollingCondition
 +	{
-+		protected enum MatchType
-+		{
-+			Nothing,
-+			Exact,
-+			Remainder,
-+		}
-+
-+		protected Tuple<int?, MatchType> Dow { get; private set; }
-+		protected Tuple<int?, MatchType> Month { get; private set; }
-+		protected Tuple<int?, MatchType> Day { get; private set; }
-+		protected Tuple<int?, MatchType> Hour { get; private set; }
-+		protected Tuple<int?, MatchType> Minute { get; private set; }
++        #region Public Instance Constructors
 +
 +        public CronRollingCondition()
 +            : this("*", "*", "*", "*", "*")
 +            Minute = TryParse(minute);
 +        }
 +
-+		public bool IsMet(string file)
++        #endregion
++
++        #region Protected Instance Properties
++
++        protected Tuple<int?, MatchType> Dow { get; private set; }
++        protected Tuple<int?, MatchType> Month { get; private set; }
++        protected Tuple<int?, MatchType> Day { get; private set; }
++        protected Tuple<int?, MatchType> Hour { get; private set; }
++        protected Tuple<int?, MatchType> Minute { get; private set; }
++
++        #endregion
++
++        #region Protected Inner Classes
++
++        protected enum MatchType
++        {
++            Nothing,
++            Exact,
++            Remainder,
++        }
++
++        #endregion
++
++        #region Protected Static Methods
++
++        /// <summary>
++        /// This method parses a string to match any of these:
++        /// i
++        /// *
++        /// */i
++        /// </summary>
++        /// <param name="input"></param>
++        /// <returns></returns>
++        static protected Tuple<int?, MatchType> TryParse(string input)
++        {
++            // trim input and strip empty spaces
++            string inputParsed = input.Trim().Replace(" ", "").Replace("\t", "");
++
++            // match anything: *
++            if (inputParsed == "*")
++            {
++                return Tuple.Create<int?, MatchType>(null, MatchType.Nothing);
++            }
++            // match a remainder: */c
++            if (inputParsed.StartsWith("*/") || inputParsed.StartsWith(@"*\"))
++            {
++                // strip first two chars
++                inputParsed = inputParsed.Substring(2);
++                // parse the remainder
++                int i = -1;
++                if (int.TryParse(inputParsed, out i))
++                {
++                    return Tuple.Create<int?, MatchType>(i, MatchType.Remainder);
++                }
++            }
++            else // match one specific numer: i
++            {
++                int i = -1;
++                if (int.TryParse(inputParsed, out i))
++                {
++                    return Tuple.Create<int?, MatchType>(i, MatchType.Exact);
++                }
++            }
++
++            // throw exception by default
++            throw new FormatException(string.Format("The input string '{0}' could not be parsed to a valid format.", input));
++        }
++
++        #endregion
++
++        #region Implementation of IRollingCondition
++
++        public bool IsMet(string file)
 +		{
 +			DateTime now = DateTime.Now;
 +			if (!IsMet(Dow, now))
 +			return true;
 +		}
 +
-+		/// <summary>
-+		/// This method parses a string to match any of these:
-+		/// i
-+		/// *
-+		/// */i
-+		/// </summary>
-+		/// <param name="input"></param>
-+		/// <returns></returns>
-+		static protected Tuple<int?, MatchType> TryParse(string input)
-+		{
-+			// trim input and strip empty spaces
-+			string inputParsed = input.Trim().Replace(" ", "").Replace("\t", "");
++        #endregion
 +
-+			// match anything: *
-+			if (inputParsed == "*")
-+			{
-+				return Tuple.Create<int?, MatchType>(null, MatchType.Nothing);
-+			}
-+			// match a remainder: */c
-+			if (inputParsed.StartsWith("*/") || inputParsed.StartsWith(@"*\"))
-+			{
-+				// strip first two chars
-+				inputParsed = inputParsed.Substring(2);
-+				// parse the remainder
-+				int i = -1;
-+				if (int.TryParse(inputParsed, out i))
-+				{
-+					return Tuple.Create<int?, MatchType>(i, MatchType.Remainder);
-+				}
-+			}
-+			else // match one specific numer: i
-+			{
-+				int i = -1;
-+				if (int.TryParse(inputParsed, out i))
-+				{
-+					return Tuple.Create<int?, MatchType>(i, MatchType.Exact);
-+				}
-+			}
++        #region Private Methods
 +
-+			// throw exception by default
-+			throw new FormatException(string.Format("The input string '{0}' could not be parsed to a valid format.", input));
-+		}
-+
-+		private bool IsMet(Tuple<int?, MatchType> match, DateTime now)
++        private bool IsMet(Tuple<int?, MatchType> match, DateTime now)
 +		{
 +			switch (match.Item2)
 +			{
 +					break;
 +			}
 +			return true;
-+		}
-+	}
++        }
++
++        #endregion
++    }
 +}
 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:21:34 2011 +0200
++++ b/src/Appender/RollingFileAppenderNGAPI/IRollingCondition.cs	Wed Sep 21 22:30:16 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:21:34 2011 +0200
++++ b/src/Appender/RollingFileAppenderNGAPI/IRollingStrategy.cs	Wed Sep 21 22:30:16 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:21:34 2011 +0200
-@@ -0,0 +1,60 @@
++++ b/src/Appender/RollingFileAppenderNGAPI/IndexRollingStrategy.cs	Wed Sep 21 22:30:16 2011 +0200
+@@ -0,0 +1,77 @@
 +#region Apache License
 +//
 +// Licensed to the Apache Software Foundation (ASF) under one or more 
 +	/// </summary>
 +	/// <author>Dominik Psenner</author>
 +	public class IndexRollingStrategy : IRollingStrategy
-+	{
-+		public void Roll(string file)
++    {
++        #region Implementation of IRollingStrategy
++
++        /// <summary>
++        /// This method rolls a file with backup indexes between
++        /// [0..10].
++        /// </summary>
++        /// <param name="file"></param>
++        public void Roll(string file)
 +		{
 +			DoRoll(file, file, 0, 10);
 +		}
 +
-+		private void DoRoll(string baseFilename, string currentFilename, int currentIndex, int maxIndex)
++        #endregion
++
++        #region Private Methods
++
++        private void DoRoll(string baseFilename, string currentFilename, int currentIndex, int maxIndex)
 +		{
 +			if (currentIndex > maxIndex)
 +			{
++                if (File.Exists(currentFilename))
++                {
++                    File.Delete(currentFilename);
++                }
 +				return;
 +			}
 +			if (!File.Exists(currentFilename))
 +			// determine next filename
 +			string nextFilename = string.Format("{0}.{1}", baseFilename, currentIndex);
 +
-+			// rename file
-+			File.Move(currentFilename, nextFilename);
-+
 +			// iterate the process until we meet the end
 +			DoRoll(baseFilename, nextFilename, currentIndex + 1, maxIndex);
-+		}
-+	}
++
++            // rename this file now that there's free room after us
++            File.Move(currentFilename, nextFilename);
++        }
++
++        #endregion
++    }
 +}
 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:21:34 2011 +0200
++++ b/src/log4net.vs2010.csproj	Wed Sep 21 22:30:16 2011 +0200
 @@ -187,6 +187,13 @@
      <Compile Include="Appender\RollingFileAppender.cs">
        <SubType>Code</SubType>