nicko 2004/11/29 08:56:16
Modified: src/Layout/Pattern DatePatternConverter.cs
src/DateFormatter AbsoluteTimeDateFormatter.cs
DateTimeDateFormatter.cs Iso8601DateFormatter.cs
src/Layout PatternLayout.cs
Added: src/Layout/Pattern UtcDatePatternConverter.cs
Log:
Added Universal date pattern: utcDate
Revision Changes Path
1.6 +71 -8
logging-log4net/src/Layout/Pattern/DatePatternConverter.cs
Index: DatePatternConverter.cs
===================================================================
RCS file:
/home/cvs/logging-log4net/src/Layout/Pattern/DatePatternConverter.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DatePatternConverter.cs 19 Aug 2004 22:29:10 -0000 1.5
+++ DatePatternConverter.cs 29 Nov 2004 16:56:16 -0000 1.6
@@ -30,10 +30,64 @@
/// Date pattern converter, uses a <see cref="IDateFormatter"/> to
format
/// the date of a <see cref="LoggingEvent"/>.
/// </summary>
+ /// <remarks>
+ /// <para>
+ /// Render the <see cref="LoggingEvent.TimeStamp"/> to the writer as a
string.
+ /// </para>
+ /// <para>
+ /// The value of the option determines the formatting of the date. The
following
+ /// values are allowed:
+ /// <list type="definition">
+ /// <item>
+ /// <term>ISO8601</term>
+ /// <description>
+ /// Uses the <see cref="Iso8601DateFormatter"/> formatter.
+ /// Formats using the <c>"YYYY-MM-dd HH:mm:ss,SSS"</c>
pattern.
+ /// </description>
+ /// </item>
+ /// <item>
+ /// <term>DATE</term>
+ /// <description>
+ /// Uses the <see cref="DateTimeDateFormatter"/> formatter.
+ /// Formats using the <c>"dd MMM YYYY HH:mm:ss,SSS"</c> for
example, <c>"06 Nov 1994 15:49:37,459"</c>.
+ /// </description>
+ /// </item>
+ /// <item>
+ /// <term>ABSOLUTE</term>
+ /// <description>
+ /// Uses the <see cref="AbsoluteTimeDateFormatter"/>
formatter.
+ /// Formats using the <c>"HH:mm:ss,SSS"</c> for example,
<c>"15:49:37,459"</c>.
+ /// </description>
+ /// </item>
+ /// <item>
+ /// <term>other</term>
+ /// <description>
+ /// Any other pattern string uses the <see
cref="SimpleDateFormatter"/> formatter.
+ /// This formatter passes the pattern string to the <see
cref="DateTime"/>
+ /// <see cref="DateTime.ToString(string)"/> method.
+ /// For details on valid patterns see
+ /// <a
href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp">DateTimeFormatInfo
Class</a>.
+ /// </description>
+ /// </item>
+ /// </list>
+ /// </para>
+ /// <para>
+ /// The <see cref="LoggingEvent.TimeStamp"/> is in the local time zone
and is rendered in that zone.
+ /// To output the time in Universal time see <see
cref="UtcDatePatternConverter"/>.
+ /// </para>
+ /// </remarks>
/// <author>Nicko Cadell</author>
- internal sealed class DatePatternConverter : PatternLayoutConverter,
IOptionHandler
+ internal class DatePatternConverter : PatternLayoutConverter,
IOptionHandler
{
- private IDateFormatter m_df;
+ /// <summary>
+ /// The <see cref="IDateFormatter"/> used to render the date to
a string
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The <see cref="IDateFormatter"/> used to render the date to
a string
+ /// </para>
+ /// </remarks>
+ protected IDateFormatter m_dateFormatter;
#region Implementation of IOptionHandler
@@ -63,26 +117,26 @@
if (string.Compare(dateFormatStr,
AbsoluteTimeDateFormatter.Iso8601TimeDateFormat, true,
System.Globalization.CultureInfo.InvariantCulture) == 0)
{
- m_df = new Iso8601DateFormatter();
+ m_dateFormatter = new Iso8601DateFormatter();
}
else if (string.Compare(dateFormatStr,
AbsoluteTimeDateFormatter.AbsoluteTimeDateFormat, true,
System.Globalization.CultureInfo.InvariantCulture) == 0)
{
- m_df = new AbsoluteTimeDateFormatter();
+ m_dateFormatter = new
AbsoluteTimeDateFormatter();
}
else if (string.Compare(dateFormatStr,
AbsoluteTimeDateFormatter.DateAndTimeDateFormat, true,
System.Globalization.CultureInfo.InvariantCulture) == 0)
{
- m_df = new DateTimeDateFormatter();
+ m_dateFormatter = new DateTimeDateFormatter();
}
else
{
try
{
- m_df = new
SimpleDateFormatter(dateFormatStr);
+ m_dateFormatter = new
SimpleDateFormatter(dateFormatStr);
}
catch (Exception e)
{
LogLog.Error("DatePatternConverter:
Could not instantiate SimpleDateFormatter with ["+dateFormatStr+"]", e);
- m_df = new Iso8601DateFormatter();
+ m_dateFormatter = new
Iso8601DateFormatter();
}
}
}
@@ -94,11 +148,20 @@
/// </summary>
/// <param name="writer"><see cref="TextWriter" /> that will
receive the formatted result.</param>
/// <param name="loggingEvent">the event being logged</param>
+ /// <remarks>
+ /// <para>
+ /// Pass the <see cref="LoggingEvent.TimeStamp"/> to the <see
cref="IDateFormatter"/>
+ /// for it to render it to the writer.
+ /// </para>
+ /// <para>
+ /// The <see cref="LoggingEvent.TimeStamp"/> passed is in the
local time zone.
+ /// </para>
+ /// </remarks>
override protected void Convert(TextWriter writer, LoggingEvent
loggingEvent)
{
try
{
- m_df.FormatDate(loggingEvent.TimeStamp, writer);
+
m_dateFormatter.FormatDate(loggingEvent.TimeStamp, writer);
}
catch (Exception ex)
{
1.1
logging-log4net/src/Layout/Pattern/UtcDatePatternConverter.cs
Index: UtcDatePatternConverter.cs
===================================================================
#region Copyright & License
//
// Copyright 2001-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Text;
using System.IO;
using log4net.Core;
using log4net.Util;
using log4net.DateFormatter;
namespace log4net.Layout.Pattern
{
/// <summary>
/// Date pattern converter, uses a <see cref="IDateFormatter"/> to
format
/// the date of a <see cref="LoggingEvent"/>.
/// </summary>
/// <remarks>
/// <para>
/// Uses a <see cref="IDateFormatter"/> to format the <see
cref="LoggingEvent.TimeStamp"/>
/// in Universal time.
/// </para>
/// <para>
/// See the <see cref="DatePatternConverter"/> for details on the date
pattern syntax.
/// </para>
/// </remarks>
/// <seealso cref="DatePatternConverter"/>
/// <author>Nicko Cadell</author>
internal class UtcDatePatternConverter : DatePatternConverter
{
/// <summary>
/// Convert the TimeStamp into a rendered message
/// </summary>
/// <param name="writer"><see cref="TextWriter" /> that will
receive the formatted result.</param>
/// <param name="loggingEvent">the event being logged</param>
/// <remarks>
/// <para>
/// Pass the <see cref="LoggingEvent.TimeStamp"/> to the <see
cref="IDateFormatter"/>
/// for it to render it to the writer.
/// </para>
/// <para>
/// The <see cref="LoggingEvent.TimeStamp"/> passed is in the
local time zone, this is converted
/// to Universal time before it is rendered.
/// </para>
/// </remarks>
/// <seealso cref="DatePatternConverter"/>
override protected void Convert(TextWriter writer, LoggingEvent
loggingEvent)
{
try
{
m_dateFormatter.FormatDate(loggingEvent.TimeStamp.ToUniversalTime(), writer);
}
catch (Exception ex)
{
LogLog.Error("UtcDatePatternConverter: Error
occurred while converting date.", ex);
}
}
}
}
1.5 +1 -1
logging-log4net/src/DateFormatter/AbsoluteTimeDateFormatter.cs
Index: AbsoluteTimeDateFormatter.cs
===================================================================
RCS file:
/home/cvs/logging-log4net/src/DateFormatter/AbsoluteTimeDateFormatter.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbsoluteTimeDateFormatter.cs 16 May 2004 21:15:15 -0000 1.4
+++ AbsoluteTimeDateFormatter.cs 29 Nov 2004 16:56:16 -0000 1.5
@@ -23,7 +23,7 @@
namespace log4net.DateFormatter
{
/// <summary>
- /// Formats a <see cref="DateTime"/> in the format "HH:mm:ss,SSS" for
example, "15:49:37,459".
+ /// Formats a <see cref="DateTime"/> in the format
<c>"HH:mm:ss,SSS"</c> for example, <c>"15:49:37,459"</c>.
/// </summary>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
1.3 +1 -1
logging-log4net/src/DateFormatter/DateTimeDateFormatter.cs
Index: DateTimeDateFormatter.cs
===================================================================
RCS file:
/home/cvs/logging-log4net/src/DateFormatter/DateTimeDateFormatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DateTimeDateFormatter.cs 16 Feb 2004 02:10:53 -0000 1.2
+++ DateTimeDateFormatter.cs 29 Nov 2004 16:56:16 -0000 1.3
@@ -23,7 +23,7 @@
namespace log4net.DateFormatter
{
/// <summary>
- /// Formats a <see cref="DateTime"/> in the format "dd MMM YYYY
HH:mm:ss,SSS" for example, "06 Nov 1994 15:49:37,459".
+ /// Formats a <see cref="DateTime"/> in the format <c>"dd MMM YYYY
HH:mm:ss,SSS"</c> for example, <c>"06 Nov 1994 15:49:37,459"</c>.
/// </summary>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
1.3 +1 -1 logging-log4net/src/DateFormatter/Iso8601DateFormatter.cs
Index: Iso8601DateFormatter.cs
===================================================================
RCS file:
/home/cvs/logging-log4net/src/DateFormatter/Iso8601DateFormatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Iso8601DateFormatter.cs 16 Feb 2004 02:10:53 -0000 1.2
+++ Iso8601DateFormatter.cs 29 Nov 2004 16:56:16 -0000 1.3
@@ -22,7 +22,7 @@
namespace log4net.DateFormatter
{
/// <summary>
- /// Formats the <see cref="DateTime"/> specified as a string:
'YYYY-MM-dd HH:mm:ss,SSS'.
+ /// Formats the <see cref="DateTime"/> specified as a string:
<c>"YYYY-MM-dd HH:mm:ss,SSS"</c>.
/// </summary>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
1.15 +39 -2 logging-log4net/src/Layout/PatternLayout.cs
Index: PatternLayout.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/Layout/PatternLayout.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- PatternLayout.cs 12 Nov 2004 22:31:25 -0000 1.14
+++ PatternLayout.cs 29 Nov 2004 16:56:16 -0000 1.15
@@ -116,7 +116,9 @@
/// <term>date</term>
/// <description>
/// <para>
- /// Used to output the date of the logging event.
The date conversion
+ /// Used to output the date of the logging event in
the local time zone.
+ /// To output the date in universal time use the
<c>%utcDate</c> pattern.
+ /// The date conversion
/// specifier may be followed by a <i>date format
specifier</i> enclosed
/// between braces. For example,
<b>%date{HH:mm:ss,fff}</b> or
/// <b>%date{dd MMM yyyy HH:mm:ss,fff}</b>. If no
date format specifier is
@@ -151,7 +153,7 @@
/// <para>
/// If an exception object is stored in the logging
event
/// it will be rendered into the pattern output
with a
- /// trainling newline.
+ /// trailing newline.
/// If there is no exception then nothing will be
output
/// and no trailing newline will be appended.
/// It is typical to put a newline before the
exception
@@ -473,6 +475,37 @@
/// </description>
/// </item>
/// <item>
+ /// <term>utcDate</term>
+ /// <description>
+ /// <para>
+ /// Used to output the date of the logging event in
universal time.
+ /// The date conversion
+ /// specifier may be followed by a <i>date format
specifier</i> enclosed
+ /// between braces. For example,
<b>%utcDate{HH:mm:ss,fff}</b> or
+ /// <b>%utcDate{dd MMM yyyy HH:mm:ss,fff}</b>. If
no date format specifier is
+ /// given then ISO8601 format is
+ /// assumed (<see
cref="log4net.DateFormatter.Iso8601DateFormatter"/>).
+ /// </para>
+ /// <para>
+ /// The date format specifier admits the same
syntax as the
+ /// time pattern string of the <see
cref="DateTime.ToString"/>.
+ /// </para>
+ /// <para>
+ /// For better results it is recommended to use the
log4net date
+ /// formatters. These can be specified using one of
the strings
+ /// "ABSOLUTE", "DATE" and "ISO8601" for specifying
+ /// <see
cref="log4net.DateFormatter.AbsoluteTimeDateFormatter"/>,
+ /// <see
cref="log4net.DateFormatter.DateTimeDateFormatter"/> and respectively
+ /// <see
cref="log4net.DateFormatter.Iso8601DateFormatter"/>. For example,
+ /// <b>%utcDate{ISO8601}</b> or
<b>%utcDate{ABSOLUTE}</b>.
+ /// </para>
+ /// <para>
+ /// These dedicated date formatters perform
significantly
+ /// better than <see
cref="DateTime.ToString(string)"/>.
+ /// </para>
+ /// </description>
+ /// </item>
+ /// <item>
/// <term>w</term>
/// <description>Equivalent to <b>username</b></description>
/// </item>
@@ -778,6 +811,10 @@
s_globalRulesRegistry.Add("u",
typeof(IdentityPatternConverter));
s_globalRulesRegistry.Add("identity",
typeof(IdentityPatternConverter));
+
+ s_globalRulesRegistry.Add("utcdate",
typeof(UtcDatePatternConverter));
+ s_globalRulesRegistry.Add("utcDate",
typeof(UtcDatePatternConverter));
+ s_globalRulesRegistry.Add("UtcDate",
typeof(UtcDatePatternConverter));
s_globalRulesRegistry.Add("w",
typeof(UserNamePatternConverter));
s_globalRulesRegistry.Add("username",
typeof(UserNamePatternConverter));