?? patternlayout.cs
字號(hào):
/// values are printed in a comma separated list.
/// </para>
/// <para>
/// The properties of an event are combined from a number of different
/// contexts. These are listed below in the order in which they are searched.
/// </para>
/// <list type="definition">
/// <item>
/// <term>the event properties</term>
/// <description>
/// The event has <see cref="LoggingEvent.Properties"/> that can be set. These
/// properties are specific to this event only.
/// </description>
/// </item>
/// <item>
/// <term>the thread properties</term>
/// <description>
/// The <see cref="ThreadContext.Properties"/> that are set on the current
/// thread. These properties are shared by all events logged on this thread.
/// </description>
/// </item>
/// <item>
/// <term>the global properties</term>
/// <description>
/// The <see cref="GlobalContext.Properties"/> that are set globally. These
/// properties are shared by all the threads in the AppDomain.
/// </description>
/// </item>
/// </list>
///
/// </description>
/// </item>
/// <item>
/// <term>r</term>
/// <description>Equivalent to <b>timestamp</b></description>
/// </item>
/// <item>
/// <term>t</term>
/// <description>Equivalent to <b>thread</b></description>
/// </item>
/// <item>
/// <term>timestamp</term>
/// <description>
/// <para>
/// Used to output the number of milliseconds elapsed since the start
/// of the application until the creation of the logging event.
/// </para>
/// </description>
/// </item>
/// <item>
/// <term>thread</term>
/// <description>
/// <para>
/// Used to output the name of the thread that generated the
/// logging event. Uses the thread number if no name is available.
/// </para>
/// </description>
/// </item>
/// <item>
/// <term>type</term>
/// <description>
/// <para>
/// Used to output the fully qualified type name of the caller
/// issuing the logging request. This conversion specifier
/// can be optionally followed by <i>precision specifier</i>, that
/// is a decimal constant in brackets.
/// </para>
/// <para>
/// If a precision specifier is given, then only the corresponding
/// number of right most components of the class name will be
/// printed. By default the class name is output in fully qualified form.
/// </para>
/// <para>
/// For example, for the class name "log4net.Layout.PatternLayout", the
/// pattern <b>%type{1}</b> will output "PatternLayout".
/// </para>
/// <para>
/// <b>WARNING</b> Generating the caller class information is
/// slow. Thus, its use should be avoided unless execution speed is
/// not an issue.
/// </para>
/// <para>
/// See the note below on the availability of caller location information.
/// </para>
/// </description>
/// </item>
/// <item>
/// <term>u</term>
/// <description>Equivalent to <b>identity</b></description>
/// </item>
/// <item>
/// <term>username</term>
/// <description>
/// <para>
/// Used to output the WindowsIdentity for the currently
/// active user.
/// </para>
/// <para>
/// <b>WARNING</b> Generating caller WindowsIdentity information is
/// extremely slow. Its use should be avoided unless execution speed
/// is not an issue.
/// </para>
/// </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(string)"/>.
/// </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>
/// <item>
/// <term>x</term>
/// <description>Equivalent to <b>ndc</b></description>
/// </item>
/// <item>
/// <term>X</term>
/// <description>Equivalent to <b>mdc</b></description>
/// </item>
/// <item>
/// <term>%</term>
/// <description>
/// <para>
/// The sequence %% outputs a single percent sign.
/// </para>
/// </description>
/// </item>
/// </list>
/// <para>
/// The single letter patterns are deprecated in favor of the
/// longer more descriptive pattern names.
/// </para>
/// <para>
/// By default the relevant information is output as is. However,
/// with the aid of format modifiers it is possible to change the
/// minimum field width, the maximum field width and justification.
/// </para>
/// <para>
/// The optional format modifier is placed between the percent sign
/// and the conversion pattern name.
/// </para>
/// <para>
/// The first optional format modifier is the <i>left justification
/// flag</i> which is just the minus (-) character. Then comes the
/// optional <i>minimum field width</i> modifier. This is a decimal
/// constant that represents the minimum number of characters to
/// output. If the data item requires fewer characters, it is padded on
/// either the left or the right until the minimum width is
/// reached. The default is to pad on the left (right justify) but you
/// can specify right padding with the left justification flag. The
/// padding character is space. If the data item is larger than the
/// minimum field width, the field is expanded to accommodate the
/// data. The value is never truncated.
/// </para>
/// <para>
/// This behavior can be changed using the <i>maximum field
/// width</i> modifier which is designated by a period followed by a
/// decimal constant. If the data item is longer than the maximum
/// field, then the extra characters are removed from the
/// <i>beginning</i> of the data item and not from the end. For
/// example, it the maximum field width is eight and the data item is
/// ten characters long, then the first two characters of the data item
/// are dropped. This behavior deviates from the printf function in C
/// where truncation is done from the end.
/// </para>
/// <para>
/// Below are various format modifier examples for the logger
/// conversion specifier.
/// </para>
/// <div class="tablediv">
/// <table class="dtTABLE" cellspacing="0">
/// <tr>
/// <th>Format modifier</th>
/// <th>left justify</th>
/// <th>minimum width</th>
/// <th>maximum width</th>
/// <th>comment</th>
/// </tr>
/// <tr>
/// <td align="center">%20logger</td>
/// <td align="center">false</td>
/// <td align="center">20</td>
/// <td align="center">none</td>
/// <td>
/// <para>
/// Left pad with spaces if the logger name is less than 20
/// characters long.
/// </para>
/// </td>
/// </tr>
/// <tr>
/// <td align="center">%-20logger</td>
/// <td align="center">true</td>
/// <td align="center">20</td>
/// <td align="center">none</td>
/// <td>
/// <para>
/// Right pad with spaces if the logger
/// name is less than 20 characters long.
/// </para>
/// </td>
/// </tr>
/// <tr>
/// <td align="center">%.30logger</td>
/// <td align="center">NA</td>
/// <td align="center">none</td>
/// <td align="center">30</td>
/// <td>
/// <para>
/// Truncate from the beginning if the logger
/// name is longer than 30 characters.
/// </para>
/// </td>
/// </tr>
/// <tr>
/// <td align="center"><nobr>%20.30logger</nobr></td>
/// <td align="center">false</td>
/// <td align="center">20</td>
/// <td align="center">30</td>
/// <td>
/// <para>
/// Left pad with spaces if the logger name is shorter than 20
/// characters. However, if logger name is longer than 30 characters,
/// then truncate from the beginning.
/// </para>
/// </td>
/// </tr>
/// <tr>
/// <td align="center">%-20.30logger</td>
/// <td align="center">true</td>
/// <td align="center">20</td>
/// <td align="center">30</td>
/// <td>
/// <para>
/// Right pad with spaces if the logger name is shorter than 20
/// characters. However, if logger name is longer than 30 characters,
/// then truncate from the beginning.
/// </para>
/// </td>
/// </tr>
/// </table>
/// </div>
/// <para>
/// <b>Note about caller location information.</b><br />
/// The following patterns <c>%type %file %line %method %location %class %C %F %L %l %M</c>
/// all generate caller location information.
/// 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>
/// <para>
/// "StackTrace information will be most informative with Debug build configurations.
/// By default, Debug builds include debug symbols, while Release builds do not. The
/// debug symbols contain most of the file, method name, line number, and column
/// information used in constructing StackFrame and StackTrace objects. StackTrace
/// might not report as many method calls as expected, due to code transformations
/// that occur during optimization."
/// </para>
/// <para>
/// 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(string, Type)"/> method.
/// </para>
/// </remarks>
/// <example>
/// This is a more detailed pattern.
/// <code><b>%timestamp [%thread] %level %logger %ndc - %message%newline</b></code>
/// </example>
/// <example>
/// A similar pattern except that the relative time is
/// right padded if less than 6 digits, thread name is right padded if
/// less than 15 characters and truncated if longer and the logger
/// name is left padded if shorter than 30 characters and truncated if
/// longer.
/// <code><b>%-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline</b></code>
/// </example>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
/// <author>Douglas de la Torre</author>
/// <author>Daniel Cazzulino</author>
public class PatternLayout : LayoutSkeleton
{
#region Constants
/// <summary>
/// Default pattern string for log output.
/// </summary>
/// <remarks>
/// <para>
/// Default pattern string for log output.
/// Currently set to the string <b>"%message%newline"</b>
/// which just prints the application supplied message.
/// </para>
/// </remarks>
public const string DefaultConversionPattern ="%message%newline";
/// <summary>
/// A detailed conversion pattern
/// </summary>
/// <remarks>
/// <para>
/// A conversion pattern which includes Time, Thread, Logger, and Nested Context.
/// Current value is <b>%timestamp [%thread] %level %logger %ndc - %message%newline</b>.
/// </para>
/// </remarks>
public const string DetailConversionPattern = "%timestamp [%thread] %level %logger %ndc - %message%newline";
#endregion
#region Static Fields
/// <summary>
/// Internal map of converter identifiers to converter types.
/// </summary>
/// <remarks>
/// <para>
/// This static map is overridden by the m_converterRegistry instance map
/// </para>
/// </remarks>
private static Hashtable s_globalRulesRegistry;
#endregion Static Fields
#region Member Variables
/// <summary>
/// the pattern
/// </summary>
private string m_pattern;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -