Author: rgrabowski
Date: Sat Apr 29 10:27:28 2006
New Revision: 398209

URL: http://svn.apache.org/viewcvs?rev=398209&view=rev
Log:
Fix for LOG4NET-59 to allow rolling files based on UTC time. Implemented by 
adding DateTimeStrategy property which accepts an IDateTime. 
RollingFileAppender contains two IDateTime inner-class implementations: 
LocalDateTime (DateTime.Now) and UniversalDateTime (DateTime.UtcNow).

Modified:
    logging/log4net/trunk/src/Appender/RollingFileAppender.cs

Modified: logging/log4net/trunk/src/Appender/RollingFileAppender.cs
URL: 
http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Appender/RollingFileAppender.cs?rev=398209&r1=398208&r2=398209&view=diff
==============================================================================
--- logging/log4net/trunk/src/Appender/RollingFileAppender.cs (original)
+++ logging/log4net/trunk/src/Appender/RollingFileAppender.cs Sat Apr 29 
10:27:28 2006
@@ -232,7 +232,6 @@
                /// </remarks>
                public RollingFileAppender() 
                {
-                       m_dateTime = new DefaultDateTime();
                }
 
                #endregion Public Instance Constructors
@@ -240,6 +239,33 @@
                #region Public Instance Properties
 
                /// <summary>
+               /// Gets or sets the strategy for determining the current date 
and time. The default
+               /// implementation is to use LocalDateTime which internally 
calls through to DateTime.Now. 
+               /// DateTime.UtcNow may be used by specifying
+               /// <see cref="RollingFileAppender.UniversalDateTime"/>.
+               /// </summary>
+               /// <value>
+               /// An implementation of the <see 
cref="RollingFileAppender.IDateTime"/> interface which returns the current date 
and time.
+               /// </value>
+               /// <remarks>
+               /// <para>
+               /// Gets or sets the <see 
cref="RollingFileAppender.IDateTime"/> used to return the current date and time.
+               /// </para>
+               /// <para>
+               /// There are two built strategies for determining the current 
date and time, 
+               /// <see cref="RollingFileAppender.LocalDateTime"/> and <see 
cref="RollingFileAppender.UniversalDateTime"/>.
+               /// </para>
+               /// <para>
+               /// The default strategy is <see 
cref="RollingFileAppender.LocalDateTime"/>.
+               /// </para>
+               /// </remarks>
+               public IDateTime DateTimeStrategy
+               {
+                       get { return m_dateTime; }
+                       set { m_dateTime = value; }
+               }
+
+               /// <summary>
                /// Gets or sets the date pattern to be used for generating 
file names
                /// when rolling over on date.
                /// </summary>
@@ -950,6 +976,11 @@
                /// </remarks>
                override public void ActivateOptions() 
                {
+                       if (m_dateTime == null)
+                       {
+                               m_dateTime = new LocalDateTime();
+                       }
+
                        if (m_rollDate && m_datePattern != null) 
                        {
                                m_now = m_dateTime.Now;
@@ -1410,7 +1441,8 @@
 
                /// <summary>
                /// This object supplies the current date/time.  Allows test 
code to plug in
-               /// a method to control this class when testing date/time based 
rolling.
+               /// a method to control this class when testing date/time based 
rolling. The default
+               /// implementation uses the underlying value of DateTime.Now.
                /// </summary>
                private IDateTime m_dateTime = null;
 
@@ -1525,7 +1557,7 @@
                /// <summary>
                /// Default implementation of <see cref="IDateTime"/> that 
returns the current time.
                /// </summary>
-               private class DefaultDateTime : IDateTime
+               private class LocalDateTime : IDateTime
                {
                        /// <summary>
                        /// Gets the <b>current</b> time.
@@ -1539,6 +1571,26 @@
                        public DateTime Now
                        {
                                get { return DateTime.Now; }
+                       }
+               }
+
+               /// <summary>
+               /// Implementation of <see cref="IDateTime"/> that returns the 
current time as the coordinated universal time (UTC).
+               /// </summary>
+               private class UniversalDateTime : IDateTime
+               {
+                       /// <summary>
+                       /// Gets the <b>current</b> time.
+                       /// </summary>
+                       /// <value>The <b>current</b> time.</value>
+                       /// <remarks>
+                       /// <para>
+                       /// Gets the <b>current</b> time.
+                       /// </para>
+                       /// </remarks>
+                       public DateTime Now
+                       {
+                               get { return DateTime.UtcNow; }
                        }
                }
 


Reply via email to