You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by bo...@apache.org on 2015/03/30 13:16:55 UTC
svn commit: r945623 [6/11] - in
/websites/production/logging/content/log4net/log4net-1.2.13: ./ release/
release/howto/ release/manual/
Modified: websites/production/logging/content/log4net/log4net-1.2.13/release/manual/configuration.html
==============================================================================
--- websites/production/logging/content/log4net/log4net-1.2.13/release/manual/configuration.html (original)
+++ websites/production/logging/content/log4net/log4net-1.2.13/release/manual/configuration.html Mon Mar 30 11:16:54 2015
@@ -1,10 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<!-- Generated by Apache Maven Doxia at Nov 18, 2013 -->
+<!-- Generated by Apache Maven Doxia at 2015-03-30 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>
- Apache log4net Manual: Configuration</title>
+ <title>Apache log4net – Apache log4net Manual: Configuration</title>
<style type="text/css" media="all">
@import url("../../css/maven-base.css");
@import url("../../css/maven-theme.css");
@@ -12,7 +11,7 @@
</style>
<link rel="stylesheet" href="../../css/print.css" type="text/css" media="print" />
<meta name="author" content="Nicko Cadell" />
- <meta name="Date-Revision-yyyymmdd" content="20131118" />
+ <meta name="Date-Revision-yyyymmdd" content="20150330" />
<meta http-equiv="Content-Language" content="en" />
<meta name="keywords" content="log4net configuration, log4net" />
</head>
@@ -27,9 +26,9 @@
</div>
<div id="breadcrumbs">
-
+
<div class="xleft">
- <span id="publishDate">Last Published: 2013-11-18</span>
+ <span id="publishDate">Last Published: 2015-03-30</span>
| <span id="projectVersion">Version: 1.2.13</span>
| <a href="http://www.apache.org/" class="externalLink" title="Apache">Apache</a>
>
@@ -37,11 +36,10 @@
>
<a href="../.././" title="log4net">log4net</a>
>
-
- Apache log4net Manual: Configuration
+ Apache log4net – Apache log4net Manual: Configuration
</div>
<div class="xright">
-
+
</div>
<div class="clear">
<hr/>
@@ -50,7 +48,7 @@
<div id="leftColumn">
<div id="navcolumn">
-
+
<h5>Apache log4net</h5>
<ul>
<li class="none">
@@ -134,12 +132,9 @@
</ul>
<h5>Project Documentation</h5>
<ul>
- <li class="collapsed">
+ <li class="collapsed">
<a href="../../project-info.html" title="Project Information">Project Information</a>
</li>
- <li class="collapsed">
- <a href="../../project-reports.html" title="Project Reports">Project Reports</a>
- </li>
</ul>
<h5>Apache</h5>
<ul>
@@ -166,7 +161,7 @@
<img class="poweredBy" alt="Built by Maven" src="../../images/logos/maven-feather.png" />
</a>
-
+
</div>
</div>
<div id="bodyColumn">
@@ -187,10 +182,15 @@ See the License for the specific languag
limitations under the License. -->
- <a name="main"></a><div class="section"><h2 id="main">Apache log4net™ Manual - Configuration</h2>
-
- <a name="config"></a><div class="section"><h2 id="config">Configuration</h2>
- <p>
+ <a name="main"></a>
+<div class="section" id="main">
+<h2><a name="Apache_log4net_Manual_-_Configuration"></a>Apache log4net™ Manual - Configuration</h2>
+
+ <a name="config"></a>
+<div class="section" id="config">
+<h2><a name="Configuration"></a>Configuration</h2>
+
+<p>
Inserting log requests into the application code requires a fair amount of
planning and effort. Observation shows that approximately 4 percent of code is
dedicated to logging. Consequently, even moderately sized applications will
@@ -198,18 +198,23 @@ limitations under the License. -->
number, it becomes imperative to manage these log statements without the need
to modify them manually.
</p>
- <p>
+
+<p>
The log4net environment is fully configurable programmatically. However, it is
far more flexible to configure log4net using configuration files. Currently,
configuration files are written in XML.
</p>
- <p>
+
+<p>
Let us give a taste of how this is done with the help of an imaginary
application
<span class="code">MyApp</span>
that uses log4net.
</p>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
using Com.Foo;
// Import log4net classes.
@@ -233,20 +238,25 @@ public class MyApp
log.Info("Exiting application.");
}
}</pre></div></div>
- <p>
+
+<p>
<span class="code">MyApp</span>
begins by importing log4net related classes. It then defines a static logger
variable with the name
<span class="code">MyApp</span>
which happens to be the fully qualified name of the class.
</p>
- <p>
+
+<p>
<span class="code">MyApp</span>
uses the following
<span class="code">Bar</span>
class:
</p>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
// Import log4net classes.
using log4net;
@@ -262,7 +272,8 @@ using log4net;
}
}
}</pre></div></div>
- <p>
+
+<p>
The invocation of the
<span class="code">BasicConfigurator.Configure()</span>
method creates a rather simple log4net setup. This method is hardwired to add
@@ -272,18 +283,23 @@ using log4net;
set to the pattern
<span class="code">"%-4timestamp [%thread] %-5level %logger %ndc - %message%newline"</span>.
</p>
- <p>
+
+<p>
Note that by default, the <i>root</i> logger is assigned to
<span class="code">Level.DEBUG</span>.
</p>
- <p>
+
+<p>
The output of <span class="code">MyApp</span> is:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
0 [main] INFO MyApp - Entering application.
36 [main] DEBUG Com.Foo.Bar - Did it again!
51 [main] INFO MyApp - Exiting application.</pre></div>
- <p>
+
+<p>
As a side note, let me mention that in log4net child loggers link only to their
existing ancestors. In particular, the logger named
<span class="code">Com.Foo.Bar</span>
@@ -296,7 +312,8 @@ using log4net;
loggers. This significantly increases performance and reduces log4net's memory
footprint.
</p>
- <p>
+
+<p>
The
<span class="code">MyApp</span>
class configures log4net by invoking
@@ -305,14 +322,18 @@ using log4net;
<span class="code">log4net</span>
namespace, retrieve the loggers they wish to use, and log away.
</p>
- <p>
+
+<p>
The previous example always outputs the same log information. Fortunately, it
is easy to modify
<span class="code">MyApp</span>
so that the log output can be controlled at run-time. Here is a slightly
modified version.
</p>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
using Com.Foo;
// Import log4net classes.
@@ -334,7 +355,8 @@ public class MyApp
log.Info("Exiting application.");
}
}</pre></div></div>
- <p>
+
+<p>
This version of
<span class="code">MyApp</span>
instructs the
@@ -342,13 +364,16 @@ public class MyApp
to parse a configuration file and set up logging accordingly. The path to the
configuration file is specified on the command line.
</p>
- <p>
+
+<p>
Here is a sample configuration file that results in exactly same output as the
previous
<span class="code">BasicConfigurator</span>
based example.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<log4net>
<!-- A1 is set to be a ConsoleAppender -->
<appender name="A1" type="log4net.Appender.ConsoleAppender">
@@ -365,14 +390,17 @@ public class MyApp
<appender-ref ref="A1" />
</root>
</log4net></pre></div>
- <p>
+
+<p>
Suppose we are no longer interested in seeing the output of any component
belonging to the
<span class="code">Com.Foo</span>
package. The following configuration file shows one possible way of achieving
this.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<log4net>
<!-- A1 is set to be a ConsoleAppender -->
<appender name="A1" type="log4net.Appender.ConsoleAppender">
@@ -395,15 +423,19 @@ public class MyApp
<level value="WARN" />
</logger>
</log4net></pre></div>
- <p>
+
+<p>
The output of
<span class="code">MyApp</span>
configured with this file is shown below.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
2000-09-07 14:07:41,508 [main] INFO MyApp - Entering application.
2000-09-07 14:07:41,529 [main] INFO MyApp - Exiting application.</pre></div>
- <p>
+
+<p>
As the logger
<span class="code">Com.Foo.Bar</span>
does not have an assigned level, it inherits its level from
@@ -414,10 +446,13 @@ public class MyApp
<span class="code">DoIt()</span>
method's log request is suppressed.
</p>
- <p>
+
+<p>
Here is another configuration file that uses multiple appenders.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<log4net>
<appender name="Console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
@@ -443,15 +478,19 @@ public class MyApp
<appender-ref ref="RollingFile" />
</root>
</log4net></pre></div>
- <p>
+
+<p>
Calling the enhanced <span class="code">MyApp</span> with the this configuration file will output the
following on the console.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
INFO [main] (MyApp.cs:16) - Entering application.
DEBUG [main] (Bar.cs:12) - Doing it again!
INFO [main] (MyApp.cs:19) - Exiting application.</pre></div>
- <p>
+
+<p>
In addition, as the <i>root</i> logger has been allocated a second appender, output
will also be directed to the
<span class="code">example.log</span>
@@ -461,7 +500,8 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
is automatically moved to
<span class="code">example.log.1</span>.
</p>
- <p>
+
+<p>
Note that to obtain these different logging behaviors we did not need to
recompile code. We could just as easily have logged to an email address,
redirected all
@@ -469,40 +509,53 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
output to an NT Event logger, or forwarded logging events to a remote log4net
server, which would log according to local server policy.
</p>
- <p>
+
+<p>
For more examples of configuring appenders using the <span class="code">XmlConfigurator</span>
see the <a href="../config-examples.html">Example Appender Configuration</a>
document.
</p>
- <a name="attributes"></a><div class="section"><h2 id="attributes">Configuration Attributes</h2>
- <p>
+ <a name="attributes"></a>
+<div class="section" id="attributes">
+<h2><a name="Configuration_Attributes"></a>Configuration Attributes</h2>
+
+<p>
The log4net configuration can be configured using assembly-level attributes rather than
specified programmatically.
</p>
- <ul>
- <li>
+
+<ul>
+
+<li>
<b>XmlConfiguratorAttribute</b>
- <p>
+
+<p>
The <span class="code">log4net.Config.XmlConfiguratorAttribute</span> Allows the
<span class="code">XmlConfigurator</span> to be configured using the following properties:
</p>
- <ul>
- <li>
+
+<ul>
+
+<li>
<b>ConfigFile</b>
- <p>
+
+<p>
If specified, this is the filename of the configuration file to use with the
<span class="code">XmlConfigurator</span>. This file path is relative to the
application base directory (<span class="code">AppDomain.CurrentDomain.BaseDirectory</span>).
</p>
- <p>
+
+<p>
This property cannot be used in conjunction with the
<span class="code">ConfigFileExtension</span> property.
</p>
</li>
- <li>
+
+<li>
<b>ConfigFileExtension</b>
- <p>
+
+<p>
If specified, this is the extension for the configuration file. The assembly
file name is used as the base name with the this extension appended. For example
if the assembly is loaded from the a file <span class="code">TestApp.exe</span>
@@ -511,34 +564,43 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
<span class="code">TestApp.exe.log4net</span>. This is equivalent to setting the
<span class="code">ConfigFile</span> property to <span class="code">TestApp.exe.log4net</span>.
</p>
- <p>
+
+<p>
The path to the configuration file is build by using the application base
directory (<span class="code">AppDomain.CurrentDomain.BaseDirectory</span>),
the assembly file name and the configuration file extension.
</p>
- <p>
+
+<p>
This property cannot be used in conjunction with the
<span class="code">ConfigFile</span> property.
</p>
</li>
- <li>
+
+<li>
<b>Watch</b>
- <p>
+
+<p>
If this flag is specified and set to <span class="code">true</span>
then the framework will watch the configuration file and will reload the config
each time the file is modified.
</p>
</li>
</ul>
- <p>
+
+<p>
If neither of the <span class="code">ConfigFile</span> or <span class="code">ConfigFileExtension</span>
properties are specified, the application configuration file (e.g. <span class="code">TestApp.exe.config</span>)
will be used as the log4net configuration file.
</p>
- <p>
+
+<p>
Example usage:
</p>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
// Configure log4net using the .config file
<b>[assembly: log4net.Config.XmlConfigurator(Watch=true)]</b>
// This will cause log4net to look for a configuration file
@@ -546,7 +608,10 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
</pre></div></div>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
// Configure log4net using the .log4net file
<b>[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]</b>
// This will cause log4net to look for a configuration file
@@ -554,12 +619,14 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
</pre></div></div>
- <p>
+
+<p>
This attribute may only be used once per assembly.
</p>
</li>
</ul>
- <p>
+
+<p>
Using attributes can be a clearer method for defining where the application's
configuration will be loaded from. However it is worth noting that attributes
are purely passive. They are information only. Therefore if you use configuration
@@ -571,8 +638,11 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</p>
</div>
- <a name="appSettings"></a><div class="section"><h2 id="appSettings">appSettings</h2>
- <p>
+ <a name="appSettings"></a>
+<div class="section" id="appSettings">
+<h2><a name="appSettings"></a>appSettings</h2>
+
+<p>
If you use <a href="#attributes">attributes</a> to
configure log4net, two settings of the
<tt>appSettings</tt> section of your
@@ -580,7 +650,8 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
override the values given in your assembly's
attributes.
</p>
- <p>
+
+<p>
The setting with the key "log4net.Config"
overrides the configuration file name (and is
considered to be relative to your application's
@@ -588,43 +659,61 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
"log4net.Config.Watch" determines whether the file
should be monitored for changes.
</p>
- <p>
+
+<p>
Even though the assembly attribute
</p>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
<b>[assembly: log4net.Config.XmlConfigurator(Watch=false)]</b>
</pre></div></div>
- <p>
+
+<p>
would configure your application to use a
configuration file "TestApp.exe.config" and not
monitor it for changes you can override this to
use the file "log4net.config" and monitor it
instead by adding
</p>
- <div class="syntax"><div class="code"><pre>
+
+<div class="syntax">
+<div>
+<pre class="code">
<appSettings>
<add key="log4net.Config" value="log4net.config"/>
<add key="log4net.Config.Watch" value="True"/>
</appSettings>
</pre></div></div>
- <p>
+
+<p>
to your application's configuration file.
</p>
</div>
- <a name="files"></a><div class="section"><h2 id="files">Configuration Files</h2>
- <p>
+ <a name="files"></a>
+<div class="section" id="files">
+<h2><a name="Configuration_Files"></a>Configuration Files</h2>
+
+<p>
Typically the log4net configuration is specified using a file. This file can
be read in one of two ways:
</p>
- <ul>
- <li>Using the .NET <span class="code">System.Configuration</span> API</li>
- <li>Reading the file contents directly</li>
+
+<ul>
+
+<li>Using the .NET <span class="code">System.Configuration</span> API</li>
+
+<li>Reading the file contents directly</li>
</ul>
- <a name="dot-config"></a><div class="section"><h2 id="dot-config">.config Files</h2>
- <p>
+ <a name="dot-config"></a>
+<div class="section" id="dot-config">
+<h2><a name="a.config_Files"></a>.config Files</h2>
+
+<p>
The <span class="code">System.Configuration</span> API is only available if the
configuration data is in the application's config file; the file named
<i>MyApp.exe.config</i> or <i>Web.config</i>. Because the <span class="code">System.Configuration</span>
@@ -634,12 +723,14 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
APIs to read the configuration data is that it requires less permissions than accessing
the configuration file directly.
</p>
- <p>
+
+<p>
The only way to configure an application using the <span class="code">System.Configuration</span>
APIs is to call the <span class="code">log4net.Config.XmlConfigurator.Configure()</span> method or
the <span class="code">log4net.Config.XmlConfigurator.Configure(ILoggerRepository)</span> method.
</p>
- <p>
+
+<p>
In order to embed the configuration data in the .config file the section name must be
identified to the .NET config file parser using a <span class="code">configSections</span> element.
The section must specify the <span class="code">log4net.Config.Log4NetConfigurationSectionHandler</span>
@@ -649,7 +740,9 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
The following is a simple example configuration file that specifies the correct
section handler to use for the log4net section.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
@@ -667,28 +760,34 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</root>
</log4net>
</configuration></pre></div>
- <p>
+
+<p>
In the above example the <span class="code">log4net</span> assembly is specified.
This assembly must be located where the .NET runtime can find it. For example it could
be located in the same directory as the application. If the log4net assembly is stored in
the GAC then the fully qualified assembly name must be specified including the culture,
version and public key.
</p>
- <p>
+
+<p>
When using the .config file to specify the configuration the section name and
XML element name must be <span class="code">log4net</span>.
</p>
</div>
- <a name="reading"></a><div class="section"><h2 id="reading">Reading Files Directly</h2>
- <p>
+ <a name="reading"></a>
+<div class="section" id="reading">
+<h2><a name="Reading_Files_Directly"></a>Reading Files Directly</h2>
+
+<p>
The XmlConfigurator can directly read any XML file and use it to configure log4net.
This includes the application's .config file; the file named <i>MyApp.exe.config</i>
or <i>Web.config</i>. The only reason not to read the configuration file directly is if the
application does not have sufficient permissions to read the file, then the configuration
must be loaded using the .NET configuration APIs (see above).
</p>
- <p>
+
+<p>
The file to read the configuration from can be specified using any of
the <span class="code">log4net.Config.XmlConfigurator</span> methods that
accept a <span class="code">System.IO.FileInfo</span> object. Because the
@@ -696,17 +795,21 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
<span class="code">ConfigureAndWatch</span> methods can be used to monitor
the configuration file for modifications and automatically reconfigure log4net.
</p>
- <p>
+
+<p>
Additionally the <span class="code">log4net.Config.XmlConfiguratorAttribute</span>
can be used to specify the file to read the configuration from.
</p>
- <p>
+
+<p>
The configuration is read from the <span class="code">log4net</span> element
in the file. Only one <span class="code">log4net</span> element can be specified
in the file but it may be located anywhere in the XML hierarchy. For example it
may be the root element:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
@@ -719,10 +822,13 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
<appender-ref ref="ConsoleAppender" />
</root>
</log4net></pre></div>
- <p>
+
+<p>
Or it may be nested within other elements:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
@@ -740,7 +846,8 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</root>
</log4net>
</configuration></pre></div>
- <p>
+
+<p>
The above example shows how the configuration data can be embedded
inside a .config file even though the file is being read directly
by log4net. An important note is that the .NET config file parser
@@ -756,20 +863,26 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</div>
- <a name="syntax"></a><div class="section"><h2 id="syntax">Configuration Syntax</h2>
- <p>
+ <a name="syntax"></a>
+<div class="section" id="syntax">
+<h2><a name="Configuration_Syntax"></a>Configuration Syntax</h2>
+
+<p>
log4net includes a configuration reader that parses an XML DOM, the
<span class="code">log4net.Config.XmlConfigurator</span>. This section defines the
syntax accepted by the configurator.
</p>
- <p>
+
+<p>
This is an example of a valid XML configuration. The root element
must be <span class="code"><log4net></span>. Note that this does not mean
that this element cannot be embedded in another XML document. See the section above
on <a href="#configuration.files">Configuration Files</a> for more information
on how to embed the XmlConfigurator XML in a configuration file.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
@@ -781,38 +894,53 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
<appender-ref ref="ConsoleAppender" />
</root>
</log4net></pre></div>
- <p>
+
+<p>
The <span class="code"><log4net></span> element supports the following attributes:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
</tr>
- <tr class="b">
- <td>debug</td>
- <td>
+
+<tr class="b">
+
+<td>debug</td>
+
+<td>
Optional attribute. Value must be either <span class="code">true</span> or <span class="code">false</span>.
The default value is <span class="code">false</span>. Set this attribute to <span class="code">true</span>
to enable internal log4net debugging for this configuration.
</td>
</tr>
- <tr class="a">
- <td>update</td>
- <td>
+
+<tr class="a">
+
+<td>update</td>
+
+<td>
Optional attribute. Value must be either <span class="code">Merge</span> or <span class="code">Overwrite</span>.
The default value is <span class="code">Merge</span>. Set this attribute to <span class="code">Overwrite</span>
to reset the configuration of the repository being configured before applying this configuration.
</td>
</tr>
- <tr class="b">
- <td>threshold</td>
- <td>
+
+<tr class="b">
+
+<td>threshold</td>
+
+<td>
Optional attribute. Value must be the name of a level registered on the repository.
The default value is <span class="code">ALL</span>. Set this attribute to limit the messages
that are logged across the whole repository, regardless of the logger that the message is logged to.
@@ -820,218 +948,305 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><log4net></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
</tr>
- <tr class="b">
- <td>appender</td>
- <td>
+
+<tr class="b">
+
+<td>appender</td>
+
+<td>
Zero or more elements allowed. Defines an appender.
</td>
</tr>
- <tr class="a">
- <td>logger</td>
- <td>
+
+<tr class="a">
+
+<td>logger</td>
+
+<td>
Zero or more elements allowed. Defines the configuration of a logger.
</td>
</tr>
- <tr class="b">
- <td>renderer</td>
- <td>
+
+<tr class="b">
+
+<td>renderer</td>
+
+<td>
Zero or more elements allowed. Defines an object renderer.
</td>
</tr>
- <tr class="a">
- <td>root</td>
- <td>
+
+<tr class="a">
+
+<td>root</td>
+
+<td>
Optional element, maximum of one allowed. Defines the configuration of the root logger.
</td>
</tr>
- <tr class="b">
- <td>param</td>
- <td>
+
+<tr class="b">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Repository specific parameters
</td>
</tr>
</table>
</div>
- <a name="appenders"></a><div class="section"><h2 id="appenders">Appenders</h2>
- <p>
+ <a name="appenders"></a>
+<div class="section" id="appenders">
+<h2><a name="Appenders"></a>Appenders</h2>
+
+<p>
Appenders may only be defined as child elements of the <span class="code"><log4net></span>
element. Each appender must be uniquely named. The implementing type for the appender must be specified.
</p>
- <p>
+
+<p>
This example shows an appender of type <span class="code">log4net.Appender.ConsoleAppender</span> being
defined. The appender will be known as <i>ConsoleAppender</i>.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender></pre></div>
- <p>
+
+<p>
The <span class="code"><appender></span> element supports the following attributes:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>name</td>
- <td>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>name</td>
+
+<td>
Required attribute. Value must be a string name for this appender. The name must be unique
among all the appenders defined in this configuration file. This name is used by the
<span class="code"><appender-ref></span> element of a Logger to reference an appender.
</td>
</tr>
- <tr class="a">
- <td>type</td>
- <td>
+
+<tr class="a">
+
+<td>type</td>
+
+<td>
Required attribute. Value must be the type name for this appender. If the appender is
not defined in the log4net assembly this type name must be fully assembly qualified.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><appender></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>appender-ref</td>
- <td>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>appender-ref</td>
+
+<td>
Zero or more elements allowed. Allows the appender to reference other appenders.
Not supported by all appenders.
</td>
</tr>
- <tr class="a">
- <td>filter</td>
- <td>
+
+<tr class="a">
+
+<td>filter</td>
+
+<td>
Zero or more elements allowed. Defines the filters used by this appender.
</td>
</tr>
- <tr class="b">
- <td>layout</td>
- <td>
+
+<tr class="b">
+
+<td>layout</td>
+
+<td>
Optional element, maximum of one allowed. Defines the layout used by this appender.
</td>
</tr>
- <tr class="a">
- <td>param</td>
- <td>
+
+<tr class="a">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Appender specific parameters.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
For examples of configuring appenders see the
<a href="../config-examples.html">Example Appender Configuration</a>
document.
</p>
- <a name="filters"></a><div class="section"><h2 id="filters">Filters</h2>
- <p>
+ <a name="filters"></a>
+<div class="section" id="filters">
+<h2><a name="Filters"></a>Filters</h2>
+
+<p>
Filters elements may only be defined as children of <span class="code"><appender></span> elements.
</p>
- <p>
+
+<p>
The <span class="code"><filter></span> element supports the following attributes:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
</tr>
- <tr class="b">
- <td>type</td>
- <td>
+
+<tr class="b">
+
+<td>type</td>
+
+<td>
Required attribute. Value must be the type name for this filter. If the filter is
not defined in the log4net assembly this type name must be fully assembly qualified.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><filter></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
</tr>
- <tr class="b">
- <td>param</td>
- <td>
+
+<tr class="b">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Filter specific parameters.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
Filters form a chain that the event has to pass through. Any filter along the way can accept the event
and stop processing, deny the event and stop processing, or allow the event on to the next filter.
If the event gets to the end of the filter chain without being denied it is implicitly accepted and will be logged.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="FATAL" />
</filter></pre></div>
- <p>
+
+<p>
This filter will deny events that have a level that is lower than <span class="code">INFO</span>
or higher than <span class="code">FATAL</span>.
All events between <span class="code">INFO</span> and <span class="code">FATAL</span> will be logged.
</p>
- <p>
+
+<p>
If we want to only allow messages through that have a specific substring (e.g. 'database')
then we need to specify the following filters:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="database" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" /></pre></div>
- <p>
+
+<p>
The first filter will look for the substring 'database' in the message text of the event.
If the text is found the filter will accept the message and filter processing will stop,
the message will be logged. If the substring is not found the event will be passed to
@@ -1040,10 +1255,13 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
logged we need to use a <span class="code">log4net.Filter.DenyAllFilter</span>
that will just deny all events that reach it. This filter is only useful at the end of the filter chain.
</p>
- <p>
+
+<p>
If we want to allow events that have either 'database' or 'ldap' in the message text we can use the following filters:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="database"/>
</filter>
@@ -1053,57 +1271,81 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
<filter type="log4net.Filter.DenyAllFilter" /></pre></div>
</div>
- <a name="layouts"></a><div class="section"><h2 id="layouts">Layouts</h2>
- <p>
+ <a name="layouts"></a>
+<div class="section" id="layouts">
+<h2><a name="Layouts"></a>Layouts</h2>
+
+<p>
Layout elements may only be defined as children of <span class="code"><appender></span> elements.
</p>
- <p>
+
+<p>
The <span class="code"><layout></span> element supports the following attributes:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
</tr>
- <tr class="b">
- <td>type</td>
- <td>
+
+<tr class="b">
+
+<td>type</td>
+
+<td>
Required attribute. Value must be the type name for this layout. If the layout is
not defined in the log4net assembly this type name must be fully assembly qualified.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><layout></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
</tr>
- <tr class="b">
- <td>param</td>
- <td>
+
+<tr class="b">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Layout specific parameters.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
This example shows how to configure a layout that uses the <span class="code">log4net.Layout.PatternLayout</span>.
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout></pre></div>
@@ -1111,52 +1353,74 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</div>
</div>
- <a name="root"></a><div class="section"><h2 id="root">Root Logger</h2>
- <p>
+ <a name="root"></a>
+<div class="section" id="root">
+<h2><a name="Root_Logger"></a>Root Logger</h2>
+
+<p>
Only one root logger element may only be defined and it must be a child of <span class="code"><log4net></span> element.
The root logger is the root of the logger hierarchy. All loggers ultimately inherit from this logger.
</p>
- <p>
+
+<p>
An example root logger:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root></pre></div>
- <p>
+
+<p>
The <span class="code"><root></span> element supports no attributes.
</p>
- <p>
+
+<p>
The <span class="code"><root></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>appender-ref</td>
- <td>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>appender-ref</td>
+
+<td>
Zero or more elements allowed. Allows the logger to reference appenders by name.
</td>
</tr>
- <tr class="a">
- <td>level</td>
- <td>
+
+<tr class="a">
+
+<td>level</td>
+
+<td>
Optional element, maximum of one allowed. Defines the logging level for this logger.
This logger will only accept event that are at this level or above.
</td>
</tr>
- <tr class="b">
- <td>param</td>
- <td>
+
+<tr class="b">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Logger specific parameters.
</td>
</tr>
@@ -1164,41 +1428,59 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</div>
</div>
- <a name="loggers"></a><div class="section"><h2 id="loggers">Loggers</h2>
- <p>
+ <a name="loggers"></a>
+<div class="section" id="loggers">
+<h2><a name="Loggers"></a>Loggers</h2>
+
+<p>
Logger elements may only be defined as children of the <span class="code"><log4net></span> element.
</p>
- <p>
+
+<p>
An example logger:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<logger name="LoggerName">
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</logger></pre></div>
- <p>
+
+<p>
The <span class="code"><logger></span> element supports the following attributes.
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>name</td>
- <td>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>name</td>
+
+<td>
Required attribute. Value must be the name of the logger.
</td>
</tr>
- <tr class="a">
- <td>additivity</td>
- <td>
+
+<tr class="a">
+
+<td>additivity</td>
+
+<td>
Optional attribute. Value may be either <span class="code">true</span> or <span class="code">false</span>.
The default value is <span class="code">true</span>. Set this attribute to <span class="code">false</span>
to prevent this logger from inheriting the appenders defined on parent loggers.
@@ -1206,35 +1488,50 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><logger></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>appender-ref</td>
- <td>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>appender-ref</td>
+
+<td>
Zero or more elements allowed. Allows the logger to reference appenders by name.
</td>
</tr>
- <tr class="a">
- <td>level</td>
- <td>
+
+<tr class="a">
+
+<td>level</td>
+
+<td>
Optional element, maximum of one allowed. Defines the logging level for this logger.
This logger will only accept event that are at this level or above.
</td>
</tr>
- <tr class="b">
- <td>param</td>
- <td>
+
+<tr class="b">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Logger specific parameters.
</td>
</tr>
@@ -1242,41 +1539,59 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</div>
</div>
- <a name="renderers"></a><div class="section"><h2 id="renderers">Renderers</h2>
- <p>
+ <a name="renderers"></a>
+<div class="section" id="renderers">
+<h2><a name="Renderers"></a>Renderers</h2>
+
+<p>
Renderer elements may only be defined as children of the <span class="code"><log4net></span> element.
</p>
- <p>
+
+<p>
An example renderer:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<renderer renderingClass="MyClass.MyRenderer" renderedClass="MyClass.MyFunkyObject" /></pre></div>
- <p>
+
+<p>
The <span class="code"><renderer></span> element supports the following attributes.
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>renderingClass</td>
- <td>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>renderingClass</td>
+
+<td>
Required attribute. Value must be the type name for this renderer. If the type is
not defined in the log4net assembly this type name must be fully assembly qualified.
This is the type of the object that will take responsibility for rendering the
<i>renderedClass</i>.
</td>
</tr>
- <tr class="a">
- <td>renderedClass</td>
- <td>
+
+<tr class="a">
+
+<td>renderedClass</td>
+
+<td>
Required attribute. Value must be the type name for the target type for this renderer. If the type is
not defined in the log4net assembly this type name must be fully assembly qualified.
This is the name of the type that this renderer will render.
@@ -1284,51 +1599,73 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><renderer></span> element supports no child elements.
</p>
</div>
- <a name="param"></a><div class="section"><h2 id="param">Parameters</h2>
- <p>
+ <a name="param"></a>
+<div class="section" id="param">
+<h2><a name="Parameters"></a>Parameters</h2>
+
+<p>
Parameter elements may be children of many elements. See the specific elements above for details.
</p>
- <p>
+
+<p>
An example param:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<param name="ConversionPattern" value="%date [%thread] %-5level %logger [%ndc] - %message%newline" /></pre></div>
- <p>
+
+<p>
The <span class="code"><param></span> element supports the following attributes.
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Attribute</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>name</td>
- <td>
+
+<tr class="a">
+
+<th>Attribute</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>name</td>
+
+<td>
Required attribute. Value must be the name of the parameter to set on the parent object.
</td>
</tr>
- <tr class="a">
- <td>value</td>
- <td>
+
+<tr class="a">
+
+<td>value</td>
+
+<td>
Optional attribute. One of <i>value</i> or <i>type</i> attributes must be specified.
The value of this attribute is a string that can be converted to the value of the
parameter.
</td>
</tr>
- <tr class="b">
- <td>type</td>
- <td>
+
+<tr class="b">
+
+<td>type</td>
+
+<td>
Optional attribute. One of <i>value</i> or <i>type</i> attributes must be specified.
The value of this attribute is a type name to create and set as the value of the
parameter. If the type is not defined in the log4net assembly this type name must
@@ -1337,64 +1674,89 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</tr>
</table>
</div>
- <p>
+
+<p>
The <span class="code"><param></span> element supports the following child elements:
</p>
- <div class="table">
- <table border="0" class="bodyTable">
+
+<div class="table">
+
+<table border="0" class="bodyTable">
<colgroup>
<col style="text-align: left; white-space: nowrap; width: 7em" />
<col style="text-align: left;" />
</colgroup>
- <tr class="a">
- <th>Element</th>
- <th>Description</th>
- </tr>
- <tr class="b">
- <td>param</td>
- <td>
+
+<tr class="a">
+
+<th>Element</th>
+
+<th>Description</th>
+ </tr>
+
+<tr class="b">
+
+<td>param</td>
+
+<td>
Zero or more elements allowed. Parameter specific parameters.
</td>
</tr>
</table>
</div>
- <p>
+
+<p>
An example param that uses nested param elements:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<param name="evaluator" type="log4net.spi.LevelEvaluator">
<param name="Threshold" value="WARN"/>
<param></pre></div>
- <a name="extension"></a><div class="section"><h2 id="extension">Extension Parameters</h2>
- <p>
+ <a name="extension"></a>
+<div class="section" id="extension">
+<h2><a name="Extension_Parameters"></a>Extension Parameters</h2>
+
+<p>
Configuration parameters map directly to writable properties on an object.
The properties available depend on the actual type of the object being
configured. The log4net SDK documentation contains the API reference for
all the components included in the log4net assembly.
</p>
- <p>
+
+<p>
For 3rd party components please see their relevant API reference for
details of the properties available.
</p>
</div>
- <a name="new-param"></a><div class="section"><h2 id="new-param">Compact Parameter Syntax</h2>
- <p>
+ <a name="new-param"></a>
+<div class="section" id="new-param">
+<h2><a name="Compact_Parameter_Syntax"></a>Compact Parameter Syntax</h2>
+
+<p>
All parameters may alternately be specified using the parameter name as the element name
rather than using the <i>param</i> element and <i>name</i> attribute.
</p>
- <p>
+
+<p>
For example a param:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<param name="evaluator" type="log4net.spi.LevelEvaluator">
<param name="Threshold" value="WARN"/>
<param></pre></div>
- <p>
+
+<p>
may be written as:
</p>
- <div class="source"><pre>
+
+<div class="source">
+<pre>
<evaluator type="log4net.spi.LevelEvaluator">
<threshold value="WARN"/>
<evaluator></pre></div>
@@ -1414,10 +1776,10 @@ DEBUG [main] (Bar.cs:12) - Doing it agai
</div>
<div id="footer">
<div class="xright">
- <div class="xright">Copyright © 2004-2013
+ <div class="xright">Copyright © 2004-2015
<a href="http://www.apache.org">Apache Software Foundation</a>.
-
+
Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache Software License, Version 2.0</a>.</div><br />
<div class="xright">Apache log4net, Apache, log4net, the Apache feather logo, the Apache Logging Services project logo and the Built by Maven logo are trademarks of The Apache Software Foundation.</div>
<div class="clear">