nicko       2004/09/19 12:50:45

  Modified:    src      log4net.csproj
               src/Layout PatternLayout.cs
               src/Layout/Pattern PatternLayoutConverter.cs
  Added:       src/Layout/Pattern ExceptionPatternConverter.cs
  Log:
  Added ExceptionPatternConverter. Updated PatternLayout to check converters 
for IgnoresException.
  
  Revision  Changes    Path
  1.10      +5 -0      logging-log4net/src/log4net.csproj
  
  Index: log4net.csproj
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/log4net.csproj,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- log4net.csproj    18 Sep 2004 14:33:35 -0000      1.9
  +++ log4net.csproj    19 Sep 2004 19:50:45 -0000      1.10
  @@ -568,6 +568,11 @@
                       BuildAction = "Compile"
                   />
                   <File
  +                    RelPath = "Layout\Pattern\ExceptionPatternConverter.cs"
  +                    SubType = "Code"
  +                    BuildAction = "Compile"
  +                />
  +                <File
                       RelPath = 
"Layout\Pattern\FileLocationPatternConverter.cs"
                       SubType = "Code"
                       BuildAction = "Compile"
  
  
  
  1.13      +43 -0     logging-log4net/src/Layout/PatternLayout.cs
  
  Index: PatternLayout.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Layout/PatternLayout.cs,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PatternLayout.cs  13 Sep 2004 07:52:07 -0000      1.12
  +++ PatternLayout.cs  19 Sep 2004 19:50:45 -0000      1.13
  @@ -142,6 +142,23 @@
        ///                     </para>
        ///                     </description>
        ///             </item>
  +     ///             <item>
  +     ///                     <term>exception</term>
  +     ///                     <description>
  +     ///                             <para>
  +     ///                             Used to output the exception passed in 
with the log message.
  +     ///                             </para>
  +     ///                             <para>
  +     ///                     If an exception object is stored in the logging 
event
  +     ///                     it will be rendered into the pattern output 
with a
  +     ///                     trainling 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
  +     ///                     and to have the exception as the last data in 
the pattern.
  +     ///                             </para>
  +     ///                     </description>
  +     ///             </item>
        ///     <item>
        ///         <term>F</term>
        ///         <description>Equivalent to <b>file</b></description>
  @@ -597,11 +614,14 @@
        /// Location information uses the <c>System.Diagnostics.StackTrace</c> 
class to generate
        /// a call stack. The caller's information is then extracted from this 
stack.
        /// </para>
  +     /// <note type="caution">
        /// <para>
        /// The <c>System.Diagnostics.StackTrace</c> class is not supported on 
the 
        /// .NET Compact Framework 1.0 therefore caller location information is 
not
        /// available on that framework.
        /// </para>
  +     /// </note>
  +     /// <note type="caution">
        /// <para>
        /// The <c>System.Diagnostics.StackTrace</c> class has this to say 
about Release builds:
        /// </para>
  @@ -617,6 +637,11 @@
        /// This means that in a Release build the caller information may be 
incomplete or may 
        /// not exist at all! Therefore caller location information cannot be 
relied upon in a Release build.
        /// </para>
  +     /// </note>
  +     /// <para>
  +     /// Additional pattern converters may be registered with a specific 
<see cref="PatternLayout"/>
  +     /// instance using the <see cref="AddConverter"/> methods.
  +     /// </para>
        /// </remarks>
        /// <example>
        /// This is a more detailed pattern.
  @@ -710,6 +735,8 @@
                        s_globalRulesRegistry.Add("d", 
typeof(DatePatternConverter));
                        s_globalRulesRegistry.Add("date", 
typeof(DatePatternConverter));
   
  +                     s_globalRulesRegistry.Add("exception", 
typeof(ExceptionPatternConverter));
  +
                        s_globalRulesRegistry.Add("F", 
typeof(FileLocationPatternConverter));
                        s_globalRulesRegistry.Add("file", 
typeof(FileLocationPatternConverter));
   
  @@ -870,6 +897,22 @@
                override public void ActivateOptions() 
                {
                        m_head = CreatePatternParser(m_pattern).Parse();
  +
  +                     PatternConverter curConverter = m_head;
  +                     while(curConverter != null)
  +                     {
  +                             if (curConverter is PatternLayoutConverter)
  +                             {
  +                                     if 
(!((PatternLayoutConverter)curConverter).IgnoresException)
  +                                     {
  +                                             // Found converter that handles 
the exception
  +                                             this.IgnoresException = false;
  +
  +                                             break;
  +                                     }
  +                             }
  +                             curConverter = curConverter.Next;
  +                     }
                }
   
                #endregion
  
  
  
  1.3       +34 -0     
logging-log4net/src/Layout/Pattern/PatternLayoutConverter.cs
  
  Index: PatternLayoutConverter.cs
  ===================================================================
  RCS file: 
/home/cvs/logging-log4net/src/Layout/Pattern/PatternLayoutConverter.cs,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PatternLayoutConverter.cs 16 Feb 2004 02:10:53 -0000      1.2
  +++ PatternLayoutConverter.cs 19 Sep 2004 19:50:45 -0000      1.3
  @@ -50,6 +50,32 @@
   
                #endregion Protected Instance Constructors
   
  +             #region Public Properties
  +
  +             /// <summary>
  +             /// Flag indicating if this converter handles the logging event 
exception
  +             /// </summary>
  +             /// <value><c>false</c> if this converter handles the logging 
event exception</value>
  +             /// <remarks>
  +             /// <para>
  +             /// If this converter handles the exception object contained 
within
  +             /// <see cref="LoggingEvent"/>, then this property should be 
set to
  +             /// <c>false</c>. Otherwise, if the layout ignores the exception
  +             /// object, then the property should be set to <c>true</c>.
  +             /// </para>
  +             /// <para>
  +             /// Set this value to override a this default setting. The 
default
  +             /// value is <c>true</c>, this converter does not handle the 
exception.
  +             /// </para>
  +             /// </remarks>
  +             virtual public bool IgnoresException 
  +             { 
  +                     get { return m_ignoresException; }
  +                     set { m_ignoresException = value; }
  +             }
  +
  +             #endregion Public Properties
  +
                #region Protected Abstract Methods
   
                /// <summary>
  @@ -83,5 +109,13 @@
                }
   
                #endregion Protected Methods
  +
  +             /// <summary>
  +             /// Flag indicating if this converter handles exceptions
  +             /// </summary>
  +             /// <remarks>
  +             /// <c>false</c> if this converter handles exceptions
  +             /// </remarks>
  +             private bool m_ignoresException = true;
        }
   }
  
  
  
  1.1                  
logging-log4net/src/Layout/Pattern/ExceptionPatternConverter.cs
  
  Index: ExceptionPatternConverter.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;
  
  namespace log4net.Layout.Pattern
  {
        /// <summary>
        /// Converter to render the exception text
        /// </summary>
        /// <remarks>
        /// If an exception object is stored in the logging event
        /// it will be rendered into the pattern output with a
        /// trainling 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
        /// and to have the exception as the last data in the pattern.
        /// </remarks>
        /// <author>Nicko Cadell</author>
        internal sealed class ExceptionPatternConverter : 
PatternLayoutConverter 
        {
                public ExceptionPatternConverter()
                {
                        // This converter handles the exception
                        this.IgnoresException = false;
                }
  
                /// <summary>
                /// Convert the pattern to the rendered message
                /// </summary>
                /// <param name="writer"><see cref="TextWriter" /> that will 
receive the formatted result.</param>
                /// <param name="loggingEvent">the event being logged</param>
                /// <returns>the relevant location information</returns>
                override protected void Convert(TextWriter writer, LoggingEvent 
loggingEvent)
                {
                        string exceptionString = 
loggingEvent.GetExceptionString();
                        if (exceptionString != null && exceptionString.Length > 
0) 
                        {
                                writer.WriteLine(exceptionString);
                        }
                }
        }
  }
  
  
  

Reply via email to