blob: 199ab10c6344577d87aaf231660e006ae7a8c83a [file] [log] [blame]
<html xmlns:MSHelp="http://msdn.microsoft.com/mshelp" xmlns:mshelp="http://msdn.microsoft.com/mshelp"><head><link rel="SHORTCUT ICON" href="./../icons/favicon.ico" /><style type="text/css">.OH_CodeSnippetContainerTabLeftActive, .OH_CodeSnippetContainerTabLeft,.OH_CodeSnippetContainerTabLeftDisabled { backgroundImageName: tabLeftBG.gif; }.OH_CodeSnippetContainerTabRightActive, .OH_CodeSnippetContainerTabRight,.OH_CodeSnippetContainerTabRightDisabled { backgroundImageName: tabRightBG.gif; }.OH_footer { backgroundImageName: footer_slice.gif; background-position: top; background-repeat: repeat-x; }</style><link rel="stylesheet" type="text/css" href="./../styles/branding.css" /><link rel="stylesheet" type="text/css" href="./../styles/branding-en-US.css" /><style type="text/css">
body
{
border-left:5px solid #e6e6e6;
overflow-x:scroll;
overflow-y:scroll;
}
</style><script src="./../scripts/branding.js" type="text/javascript"><!----></script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>PatternLayout Class</title><meta name="Language" content="en-us" /><meta name="System.Keywords" content="PatternLayout class" /><meta name="System.Keywords" content="log4net.Layout.PatternLayout class" /><meta name="System.Keywords" content="PatternLayout class, about PatternLayout class" /><meta name="Microsoft.Help.F1" content="log4net.Layout.PatternLayout" /><meta name="Microsoft.Help.Id" content="T:log4net.Layout.PatternLayout" /><meta name="Description" content="A flexible layout configurable with pattern string." /><meta name="Microsoft.Help.ContentType" content="Reference" /><meta name="BrandingAware" content="'true'" /><meta name="container" content="log4net.Layout" /><meta name="file" content="T_log4net_Layout_PatternLayout" /><meta name="guid" content="T_log4net_Layout_PatternLayout" /><link type="text/css" rel="stylesheet" href="ms-help://Hx/HxRuntime/HxLink.css" /><link type="text/css" rel="stylesheet" href="./../styles/highlight.css" /><script type="text/javascript" src="../scripts/highlight.js"><!----></script><meta name="SelfBranded" content="true" /></head><body onload="onLoad()" class="primary-mtps-offline-document"><div class="OH_outerDiv"><div class="OH_outerContent"><table class="TitleTable"><tr><td class="OH_tdTitleColumn">PatternLayout Class</td><td class="OH_tdRunningTitleColumn">Apache log4net™ SDK Documentation</td></tr></table><div id="mainSection"><div id="mainBody"><span class="introStyle"></span><div class="summary">
A flexible layout configurable with pattern string.
</div><div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Inheritance Hierarchy</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"></div><img src="./../icons/online_icon.gif" class="OH_offlineIcon" alt="Online" title="Online" /><a href="http://msdn2.microsoft.com/en-us/library/e5kfa45b" target="_blank">System<span id="ID0EBKPAAAAA"> </span><script type="text/javascript">
addToLanSpecTextIdSet("ID0EBKPAAAAA?vb=.|cpp=::|cs=.|fs=.|nu=.");
</script>Object</a><br />  <a href="T_log4net_Layout_LayoutSkeleton.htm" target="">log4net.Layout<span id="ID0EBHPAAAAA"> </span><script type="text/javascript">
addToLanSpecTextIdSet("ID0EBHPAAAAA?vb=.|cpp=::|cs=.|fs=.|nu=.");
</script>LayoutSkeleton</a><br />    <span class="selflink">log4net.Layout<span id="ID0EBEPAAAAA"> </span><script type="text/javascript">
addToLanSpecTextIdSet("ID0EBEPAAAAA?vb=.|cpp=::|cs=.|fs=.|nu=.");
</script>PatternLayout</span><br />      <a href="T_log4net_Layout_DynamicPatternLayout.htm" target="">log4net.Layout<span id="ID0EBBPAAAAA"> </span><script type="text/javascript">
addToLanSpecTextIdSet("ID0EBBPAAAAA?vb=.|cpp=::|cs=.|fs=.|nu=.");
</script>DynamicPatternLayout</a><br /><p></p><b>Namespace:</b> <a href="N_log4net_Layout.htm" target="">log4net.Layout</a><br /><b>Assembly:</b> <span sdata="assembly">log4net</span> (in log4net.dll) Version: 1.2.15.0 (1.2.15.0)<div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Syntax</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"></div><div id="snippetGroup_Syntax" class="code"><div id="ID0ECAFAAAAA" class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs" id="ID0ECAFAAAAA_tabs"><div class="OH_CodeSnippetContainerTabLeftActive" id="ID0ECAFAAAAA_tabimgleft"></div><div id="ID0ECAFAAAAA_tab1" class="OH_CodeSnippetContainerTabActive" EnableCopyCode="true"><a href="#" onclick="javascript:ChangeTab('ID0ECAFAAAAA','C#','1','4');return false;">C#</a></div><div id="ID0ECAFAAAAA_tab2" class="OH_CodeSnippetContainerTab" EnableCopyCode="true"><a href="#" onclick="javascript:ChangeTab('ID0ECAFAAAAA','Visual Basic','2','4');return false;">VB</a></div><div id="ID0ECAFAAAAA_tab3" class="OH_CodeSnippetContainerTab" EnableCopyCode="true"><a href="#" onclick="javascript:ChangeTab('ID0ECAFAAAAA','Visual C++','3','4');return false;">C++</a></div><div id="ID0ECAFAAAAA_tab4" class="OH_CodeSnippetContainerTabDisabledNotFirst" EnableCopyCode="true" disabled="true"><a>F#</a></div><div class="OH_CodeSnippetContainerTabRight" id="ID0ECAFAAAAA_tabimgright"></div></div><div id="ID0ECAFAAAAA_codecollection" class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0ECAFAAAAA_ViewColorized" href="#" onclick="javascript:ExchangeTitleContent('ID0ECAFAAAAA','4')" title="View Colorized" style="display: none">View Colorized</a><a id="ID0ECAFAAAAA_copycode" href="#" onclick="javascript:CopyToClipboard('ID0ECAFAAAAA','4')" title="Copy to Clipboard">Copy to Clipboard</a><a id="ID0ECAFAAAAA_PrintText" class="OH_PrintText" href="#" onclick="javascript:Print('ID0ECAFAAAAA','4')" title="Print">Print</a></div></div><div id="ID0ECAFAAAAA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre><span class="keyword">public</span> <span class="keyword">class</span> <span class="identifier">PatternLayout</span> : <span class="identifier">LayoutSkeleton</span></pre></div><div id="ID0ECAFAAAAA_code_Plain_Div1" class="OH_CodeSnippetContainerCode" style="display: none"><pre>public class PatternLayout : LayoutSkeleton</pre></div><div id="ID0ECAFAAAAA_code_Div2" class="OH_CodeSnippetContainerCode" style="display: none"><pre><span class="keyword">Public</span> <span class="keyword">Class</span> <span class="identifier">PatternLayout</span> 
<span class="keyword">Inherits</span> <span class="identifier">LayoutSkeleton</span></pre></div><div id="ID0ECAFAAAAA_code_Plain_Div2" class="OH_CodeSnippetContainerCode" style="display: none"><pre>Public Class PatternLayout 
Inherits LayoutSkeleton</pre></div><div id="ID0ECAFAAAAA_code_Div3" class="OH_CodeSnippetContainerCode" style="display: none"><pre><span class="keyword">public</span> <span class="keyword">ref class</span> <span class="identifier">PatternLayout</span> : <span class="keyword">public</span> <span class="identifier">LayoutSkeleton</span></pre></div><div id="ID0ECAFAAAAA_code_Plain_Div3" class="OH_CodeSnippetContainerCode" style="display: none"><pre>public ref class PatternLayout : public LayoutSkeleton</pre></div><div id="ID0ECAFAAAAA_code_Div4" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div><div id="ID0ECAFAAAAA_code_Plain_Div4" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div></div></div><script>addSpecificTextLanguageTagSet('ID0ECAFAAAAA');</script></div><div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Remarks</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"></div><p>
The goal of this class is to <span class="nolink">Format(TextWriter, LoggingEvent)</span> a
<a href="T_log4net_Core_LoggingEvent.htm" target="">LoggingEvent</a> as a string. The results
depend on the <i>conversion pattern</i>.
</p><p>
The conversion pattern is closely related to the conversion
pattern of the printf function in C. A conversion pattern is
composed of literal text and format control expressions called
<i>conversion specifiers</i>.
</p><p><i>You are free to insert any literal text within the conversion
pattern.</i></p><p>
Each conversion specifier starts with a percent sign (%) and is
followed by optional <i>format modifiers</i> and a <i>conversion
pattern name</i>. The conversion pattern name specifies the type of
data, e.g. logger, level, date, thread name. The format
modifiers control such things as field width, padding, left and
right justification. The following is a simple example.
</p><p>
Let the conversion pattern be <b>"%-5level [%thread]: %message%newline"</b> and assume
that the log4net environment was set to use a PatternLayout. Then the
statements
</p><div id="ID0EQEAAAAA" class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs" id="ID0EQEAAAAA_tabs"><div class="OH_CodeSnippetContainerTabLeftActive" id="ID0EQEAAAAA_tabimgleft"></div><div id="ID0EQEAAAAA_tab1" class="OH_CodeSnippetContainerTabActive" EnableCopyCode="true"><a href="#" onclick="javascript:ChangeTab('ID0EQEAAAAA','C#','1','4');return false;">C#</a></div><div id="ID0EQEAAAAA_tab2" class="OH_CodeSnippetContainerTabDisabledNotFirst" EnableCopyCode="true" disabled="true"><a>VB</a></div><div id="ID0EQEAAAAA_tab3" class="OH_CodeSnippetContainerTabDisabledNotFirst" EnableCopyCode="true" disabled="true"><a>C++</a></div><div id="ID0EQEAAAAA_tab4" class="OH_CodeSnippetContainerTabDisabledNotFirst" EnableCopyCode="true" disabled="true"><a>F#</a></div><div class="OH_CodeSnippetContainerTabRight" id="ID0EQEAAAAA_tabimgright"></div></div><div id="ID0EQEAAAAA_codecollection" class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EQEAAAAA_ViewColorized" href="#" onclick="javascript:ExchangeTitleContent('ID0EQEAAAAA','4')" title="View Colorized" style="display: none">View Colorized</a><a id="ID0EQEAAAAA_copycode" href="#" onclick="javascript:CopyToClipboard('ID0EQEAAAAA','4')" title="Copy to Clipboard">Copy to Clipboard</a><a id="ID0EQEAAAAA_PrintText" class="OH_PrintText" href="#" onclick="javascript:Print('ID0EQEAAAAA','4')" title="Print">Print</a></div></div><div id="ID0EQEAAAAA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre>ILog log = LogManager.GetLogger(<span class="highlight-keyword">typeof</span>(TestApp));
log.Debug(<span class="highlight-literal">"Message 1"</span>);
log.Warn(<span class="highlight-literal">"Message 2"</span>);</pre></div><div id="ID0EQEAAAAA_code_Plain_Div1" class="OH_CodeSnippetContainerCode" style="display: none"><pre>ILog log = LogManager.GetLogger(typeof(TestApp));
log.Debug("Message 1");
log.Warn("Message 2");</pre></div><div id="ID0EQEAAAAA_code_Div2" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div><div id="ID0EQEAAAAA_code_Plain_Div2" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div><div id="ID0EQEAAAAA_code_Div3" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div><div id="ID0EQEAAAAA_code_Plain_Div3" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div><div id="ID0EQEAAAAA_code_Div4" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div><div id="ID0EQEAAAAA_code_Plain_Div4" class="OH_CodeSnippetContainerCode" style="display: none"><pre /></div></div></div><script>addSpecificTextLanguageTagSet('ID0EQEAAAAA');</script><p>would yield the output</p><div id="ID0EOEAAAAA" class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs" id="ID0EOEAAAAA_tabs"></div><div id="ID0EOEAAAAA_codecollection" class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EOEAAAAA_ViewColorized" href="#" onclick="javascript:ExchangeTitleContent('ID0EOEAAAAA','4')" title="View Colorized" style="display: none">View Colorized</a><a id="ID0EOEAAAAA_copycode" href="#" onclick="javascript:CopyToClipboard('ID0EOEAAAAA','4')" title="Copy to Clipboard">Copy to Clipboard</a><a id="ID0EOEAAAAA_PrintText" class="OH_PrintText" href="#" onclick="javascript:Print('ID0EOEAAAAA','4')" title="Print">Print</a></div></div><div id="ID0EOEAAAAA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre>DEBUG [main]: Message <span class="highlight-number">1</span>
WARN [main]: Message <span class="highlight-number">2</span></pre></div><div id="ID0EOEAAAAA_code_Plain_Div1" class="OH_CodeSnippetContainerCode" style="display: none"><pre>DEBUG [main]: Message 1
WARN [main]: Message 2</pre></div></div></div><script>addSpecificTextLanguageTagSet('ID0EOEAAAAA');</script><p>
Note that there is no explicit separator between text and
conversion specifiers. The pattern parser knows when it has reached
the end of a conversion specifier when it reads a conversion
character. In the example above the conversion specifier
<b>%-5level</b> means the level of the logging event should be left
justified to a width of five characters.
</p><p>
The recognized conversion pattern names are:
</p><div class="tableSection"><table><tr><th>Conversion Pattern Name</th><th>Effect</th></tr><tr><td>a</td><td>Equivalent to <b>appdomain</b></td></tr><tr><td>appdomain</td><td>
Used to output the friendly name of the AppDomain where the
logging event was generated.
</td></tr><tr><td>aspnet-cache</td><td>
Used to output all cache items in the case of <b>%aspnet-cache</b> or just one named item if used as <b>%aspnet-cache{key}</b><p>
This pattern is not available for Compact Framework or Client Profile assemblies.
</p></td></tr><tr><td>aspnet-context</td><td>
Used to output all context items in the case of <b>%aspnet-context</b> or just one named item if used as <b>%aspnet-context{key}</b><p>
This pattern is not available for Compact Framework or Client Profile assemblies.
</p></td></tr><tr><td>aspnet-request</td><td>
Used to output all request parameters in the case of <b>%aspnet-request</b> or just one named param if used as <b>%aspnet-request{key}</b><p>
This pattern is not available for Compact Framework or Client Profile assemblies.
</p></td></tr><tr><td>aspnet-session</td><td>
Used to output all session items in the case of <b>%aspnet-session</b> or just one named item if used as <b>%aspnet-session{key}</b><p>
This pattern is not available for Compact Framework or Client Profile assemblies.
</p></td></tr><tr><td>c</td><td>Equivalent to <b>logger</b></td></tr><tr><td>C</td><td>Equivalent to <b>type</b></td></tr><tr><td>class</td><td>Equivalent to <b>type</b></td></tr><tr><td>d</td><td>Equivalent to <b>date</b></td></tr><tr><td>date</td><td>
Used to output the date of the logging event in the local time zone.
To output the date in universal time use the <span class="code">%utcdate</span> 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
given then ISO8601 format is
assumed (<a href="T_log4net_DateFormatter_Iso8601DateFormatter.htm" target="">Iso8601DateFormatter</a>).
<p>
The date format specifier admits the same syntax as the
time pattern string of the <span class="nolink">ToString(string)</span>.
</p><p>
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
<a href="T_log4net_DateFormatter_AbsoluteTimeDateFormatter.htm" target="">AbsoluteTimeDateFormatter</a>,
<a href="T_log4net_DateFormatter_DateTimeDateFormatter.htm" target="">DateTimeDateFormatter</a> and respectively
<a href="T_log4net_DateFormatter_Iso8601DateFormatter.htm" target="">Iso8601DateFormatter</a>. For example,
<b>%date{ISO8601}</b> or <b>%date{ABSOLUTE}</b>.
</p><p>
These dedicated date formatters perform significantly
better than <span class="nolink">ToString(string)</span>.
</p></td></tr><tr><td>exception</td><td>
Used to output the exception passed in with the log message.
<p>
If an exception object is stored in the logging event
it will be rendered into the pattern output with a
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
and to have the exception as the last data in the pattern.
</p></td></tr><tr><td>F</td><td>Equivalent to <b>file</b></td></tr><tr><td>file</td><td>
Used to output the file name where the logging request was
issued.
<p><b>WARNING</b> Generating caller location information is
extremely slow. Its use should be avoided unless execution speed
is not an issue.
</p><p>
See the note below on the availability of caller location information.
</p></td></tr><tr><td>identity</td><td>
Used to output the user name for the currently active user
(Principal.Identity.Name).
<p><b>WARNING</b> Generating caller information is
extremely slow. Its use should be avoided unless execution speed
is not an issue.
</p></td></tr><tr><td>l</td><td>Equivalent to <b>location</b></td></tr><tr><td>L</td><td>Equivalent to <b>line</b></td></tr><tr><td>location</td><td>
Used to output location information of the caller which generated
the logging event.
<p>
The location information depends on the CLI implementation but
usually consists of the fully qualified name of the calling
method followed by the callers source the file name and line
number between parentheses.
</p><p>
The location information can be very useful. However, its
generation is <b>extremely</b> slow. Its use should be avoided
unless execution speed is not an issue.
</p><p>
See the note below on the availability of caller location information.
</p></td></tr><tr><td>level</td><td>
Used to output the level of the logging event.
</td></tr><tr><td>line</td><td>
Used to output the line number from where the logging request
was issued.
<p><b>WARNING</b> Generating caller location information is
extremely slow. Its use should be avoided unless execution speed
is not an issue.
</p><p>
See the note below on the availability of caller location information.
</p></td></tr><tr><td>logger</td><td>
Used to output the logger of the logging event. The
logger conversion specifier can be optionally followed by
<i>precision specifier</i>, that is a decimal constant in
brackets.
<p>
If a precision specifier is given, then only the corresponding
number of right most components of the logger name will be
printed. By default the logger name is printed in full.
</p><p>
For example, for the logger name "a.b.c" the pattern
<b>%logger{2}</b> will output "b.c".
</p></td></tr><tr><td>m</td><td>Equivalent to <b>message</b></td></tr><tr><td>M</td><td>Equivalent to <b>method</b></td></tr><tr><td>message</td><td>
Used to output the application supplied message associated with
the logging event.
</td></tr><tr><td>mdc</td><td>
The MDC (old name for the ThreadContext.Properties) is now part of the
combined event properties. This pattern is supported for compatibility
but is equivalent to <b>property</b>.
</td></tr><tr><td>method</td><td>
Used to output the method name where the logging request was
issued.
<p><b>WARNING</b> Generating caller location information is
extremely slow. Its use should be avoided unless execution speed
is not an issue.
</p><p>
See the note below on the availability of caller location information.
</p></td></tr><tr><td>n</td><td>Equivalent to <b>newline</b></td></tr><tr><td>newline</td><td>
Outputs the platform dependent line separator character or
characters.
<p>
This conversion pattern offers the same performance as using
non-portable line separator strings such as "\n", or "\r\n".
Thus, it is the preferred way of specifying a line separator.
</p></td></tr><tr><td>ndc</td><td>
Used to output the NDC (nested diagnostic context) associated
with the thread that generated the logging event.
</td></tr><tr><td>p</td><td>Equivalent to <b>level</b></td></tr><tr><td>P</td><td>Equivalent to <b>property</b></td></tr><tr><td>properties</td><td>Equivalent to <b>property</b></td></tr><tr><td>property</td><td>
Used to output the an event specific property. The key to
lookup must be specified within braces and directly following the
pattern specifier, e.g. <b>%property{user}</b> would include the value
from the property that is keyed by the string 'user'. Each property value
that is to be included in the log must be specified separately.
Properties are added to events by loggers or appenders. By default
the <span class="code">log4net:HostName</span> property is set to the name of machine on
which the event was originally logged.
<p>
If no key is specified, e.g. <b>%property</b> then all the keys and their
values are printed in a comma separated list.
</p><p>
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.
</p><dl class="authored"><dt>the event properties</dt><dd>
The event has <a href="P_log4net_Core_LoggingEvent_Properties.htm" target="">Properties</a> that can be set. These
properties are specific to this event only.
</dd><dt>the thread properties</dt><dd>
The <a href="P_log4net_ThreadContext_Properties.htm" target="">Properties</a> that are set on the current
thread. These properties are shared by all events logged on this thread.
</dd><dt>the global properties</dt><dd>
The <a href="P_log4net_GlobalContext_Properties.htm" target="">Properties</a> that are set globally. These
properties are shared by all the threads in the AppDomain.
</dd></dl></td></tr><tr><td>r</td><td>Equivalent to <b>timestamp</b></td></tr><tr><td>stacktrace</td><td>
Used to output the stack trace of the logging event
The stack trace level specifier may be enclosed
between braces. For example, <b>%stacktrace{level}</b>.
If no stack trace level specifier is given then 1 is assumed
<p>
Output uses the format:
type3.MethodCall3 &gt; type2.MethodCall2 &gt; type1.MethodCall1
</p><p>
This pattern is not available for Compact Framework assemblies.
</p></td></tr><tr><td>stacktracedetail</td><td>
Used to output the stack trace of the logging event
The stack trace level specifier may be enclosed
between braces. For example, <b>%stacktracedetail{level}</b>.
If no stack trace level specifier is given then 1 is assumed
<p>
Output uses the format:
type3.MethodCall3(type param,...) &gt; type2.MethodCall2(type param,...) &gt; type1.MethodCall1(type param,...)
</p><p>
This pattern is not available for Compact Framework assemblies.
</p></td></tr><tr><td>t</td><td>Equivalent to <b>thread</b></td></tr><tr><td>timestamp</td><td>
Used to output the number of milliseconds elapsed since the start
of the application until the creation of the logging event.
</td></tr><tr><td>thread</td><td>
Used to output the name of the thread that generated the
logging event. Uses the thread number if no name is available.
</td></tr><tr><td>type</td><td>
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.
<p>
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.
</p><p>
For example, for the class name "log4net.Layout.PatternLayout", the
pattern <b>%type{1}</b> will output "PatternLayout".
</p><p><b>WARNING</b> Generating the caller class information is
slow. Thus, its use should be avoided unless execution speed is
not an issue.
</p><p>
See the note below on the availability of caller location information.
</p></td></tr><tr><td>u</td><td>Equivalent to <b>identity</b></td></tr><tr><td>username</td><td>
Used to output the WindowsIdentity for the currently
active user.
<p><b>WARNING</b> Generating caller WindowsIdentity information is
extremely slow. Its use should be avoided unless execution speed
is not an issue.
</p></td></tr><tr><td>utcdate</td><td>
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 (<a href="T_log4net_DateFormatter_Iso8601DateFormatter.htm" target="">Iso8601DateFormatter</a>).
<p>
The date format specifier admits the same syntax as the
time pattern string of the <span class="nolink">ToString(string)</span>.
</p><p>
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
<a href="T_log4net_DateFormatter_AbsoluteTimeDateFormatter.htm" target="">AbsoluteTimeDateFormatter</a>,
<a href="T_log4net_DateFormatter_DateTimeDateFormatter.htm" target="">DateTimeDateFormatter</a> and respectively
<a href="T_log4net_DateFormatter_Iso8601DateFormatter.htm" target="">Iso8601DateFormatter</a>. For example,
<b>%utcdate{ISO8601}</b> or <b>%utcdate{ABSOLUTE}</b>.
</p><p>
These dedicated date formatters perform significantly
better than <span class="nolink">ToString(string)</span>.
</p></td></tr><tr><td>w</td><td>Equivalent to <b>username</b></td></tr><tr><td>x</td><td>Equivalent to <b>ndc</b></td></tr><tr><td>X</td><td>Equivalent to <b>mdc</b></td></tr><tr><td>%</td><td>
The sequence %% outputs a single percent sign.
</td></tr></table></div><p>
The single letter patterns are deprecated in favor of the
longer more descriptive pattern names.
</p><p>
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.
</p><p>
The optional format modifier is placed between the percent sign
and the conversion pattern name.
</p><p>
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.
</p><p>
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.
</p><p>
Below are various format modifier examples for the logger
conversion specifier.
</p><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><p>
Left pad with spaces if the logger name is less than 20
characters long.
</p></td></tr><tr><td align="center">%-20logger</td><td align="center">true</td><td align="center">20</td><td align="center">none</td><td><p>
Right pad with spaces if the logger
name is less than 20 characters long.
</p></td></tr><tr><td align="center">%.30logger</td><td align="center">NA</td><td align="center">none</td><td align="center">30</td><td><p>
Truncate from the beginning if the logger
name is longer than 30 characters.
</p></td></tr><tr><td align="center">%20.30logger</td><td align="center">false</td><td align="center">20</td><td align="center">30</td><td><p>
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.
</p></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><p>
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.
</p></td></tr></table></div><p><b>Note about caller location information.</b><br />
The following patterns <span class="code">%type %file %line %method %location %class %C %F %L %l %M</span>
all generate caller location information.
Location information uses the <span class="code">System.Diagnostics.StackTrace</span> class to generate
a call stack. The caller's information is then extracted from this stack.
</p><div class="alert"><table><tr><th><img class="mtps-img-src" src="./../icons/alert_caution.gif" alt="Caution note" /> <b>Caution</b></th></tr><tr><td>
The <span class="code">System.Diagnostics.StackTrace</span> class is not supported on the
.NET Compact Framework 1.0 therefore caller location information is not
available on that framework.
</td></tr></table></div><div class="alert"><table><tr><th><img class="mtps-img-src" src="./../icons/alert_caution.gif" alt="Caution note" /> <b>Caution</b></th></tr><tr><td><p>
The <span class="code">System.Diagnostics.StackTrace</span> class has this to say about Release builds:
</p><p>
"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."
</p><p>
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.
</p></td></tr></table></div><p>
Additional pattern converters may be registered with a specific <span class="selflink">PatternLayout</span>
instance using the <span class="nolink">[M:AddConverter(string, Type)]</span> method.
</p><div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Examples</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"></div>
This is a more detailed pattern.
<div id="ID0EADAAAAA" class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs" id="ID0EADAAAAA_tabs"></div><div id="ID0EADAAAAA_codecollection" class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EADAAAAA_ViewColorized" href="#" onclick="javascript:ExchangeTitleContent('ID0EADAAAAA','4')" title="View Colorized" style="display: none">View Colorized</a><a id="ID0EADAAAAA_copycode" href="#" onclick="javascript:CopyToClipboard('ID0EADAAAAA','4')" title="Copy to Clipboard">Copy to Clipboard</a><a id="ID0EADAAAAA_PrintText" class="OH_PrintText" href="#" onclick="javascript:Print('ID0EADAAAAA','4')" title="Print">Print</a></div></div><div id="ID0EADAAAAA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre>&lt;b&gt;%timestamp [%thread] %level %logger %ndc - %message%newline&lt;/b&gt;</pre></div><div id="ID0EADAAAAA_code_Plain_Div1" class="OH_CodeSnippetContainerCode" style="display: none"><pre>&lt;b&gt;%timestamp [%thread] %level %logger %ndc - %message%newline&lt;/b&gt;</pre></div></div></div><script>addSpecificTextLanguageTagSet('ID0EADAAAAA');</script><div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">Examples</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"></div>
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.
<div id="ID0EACAAAAA" class="OH_CodeSnippetContainer"><div class="OH_CodeSnippetContainerTabs" id="ID0EACAAAAA_tabs"></div><div id="ID0EACAAAAA_codecollection" class="OH_CodeSnippetContainerCodeCollection"><div class="OH_CodeSnippetToolBar"><div class="OH_CodeSnippetToolBarText"><a id="ID0EACAAAAA_ViewColorized" href="#" onclick="javascript:ExchangeTitleContent('ID0EACAAAAA','4')" title="View Colorized" style="display: none">View Colorized</a><a id="ID0EACAAAAA_copycode" href="#" onclick="javascript:CopyToClipboard('ID0EACAAAAA','4')" title="Copy to Clipboard">Copy to Clipboard</a><a id="ID0EACAAAAA_PrintText" class="OH_PrintText" href="#" onclick="javascript:Print('ID0EACAAAAA','4')" title="Print">Print</a></div></div><div id="ID0EACAAAAA_code_Div1" class="OH_CodeSnippetContainerCode" style="display: block"><pre>&lt;b&gt;%<span class="highlight-number">-6</span>timestamp [%<span class="highlight-number">15.15</span>thread] %<span class="highlight-number">-5</span>level %<span class="highlight-number">30.30</span>logger %ndc - %message%newline&lt;/b&gt;</pre></div><div id="ID0EACAAAAA_code_Plain_Div1" class="OH_CodeSnippetContainerCode" style="display: none"><pre>&lt;b&gt;%-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline&lt;/b&gt;</pre></div></div></div><script>addSpecificTextLanguageTagSet('ID0EACAAAAA');</script><a name="seeAlsoSection"><!----></a><div class="OH_CollapsibleAreaRegion"><div class="OH_regiontitle">See Also</div><div class="OH_CollapsibleArea_HrDiv"><hr class="OH_CollapsibleArea_Hr" /></div></div><div class="OH_clear"></div><div class="seeAlsoStyle"><a href="AllMembers_T_log4net_Layout_PatternLayout.htm" target="">PatternLayout Members</a></div><div class="seeAlsoStyle"><a href="N_log4net_Layout.htm" target="">log4net.Layout Namespace</a></div></div></div></div></div><div id="OH_footer" class="OH_footer"><p>Apache log4net, Apache and log4net are trademarks of The Apache Software Foundation.</p><p><a href="http://logging.apache.org/log4net/" target="_blank"><img src="./../icons/online_icon.gif" class="OH_offlineIcon" alt="Online" title="Online" /> 
Copyright 2004-2015 The Apache Software Foundation (http://logging.apache.org/log4net/)</a></p><div class="OH_feedbacklink"><a href="mailto:http://logging.apache.org/log4net/mail-lists.html?subject=Apache+log4net%e2%84%a2+SDK+Documentation+PatternLayout+Class+100+EN-US&amp;body=Your%20feedback%20is%20used%20to%20improve%20the%20documentation%20and%20the%20product.%20Your%20e-mail%20address%20will%20not%20be%20used%20for%20any%20other%20purpose%20and%20is%20disposed%20of%20after%20the%20issue%20you%20report%20is%20resolved.%20While%20working%20to%20resolve%20the%20issue%20that%20you%20report%2c%20you%20may%20be%20contacted%20via%20e-mail%20to%20get%20further%20details%20or%20clarification%20on%20the%20feedback%20you%20sent.%20After%20the%20issue%20you%20report%20has%20been%20addressed%2c%20you%20may%20receive%20an%20e-mail%20to%20let%20you%20know%20that%20your%20feedback%20has%20been%20addressed.">Send Feedback</a> on this topic to http://logging.apache.org/log4net/mail-lists.html.</div></div></body></html>