| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <!-- Generated by Apache Maven Doxia at 2017-04-28 --> |
| <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 – Apache log4net: Examples - Apache log4net</title> |
| <link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css" /> |
| <link rel="stylesheet" href="../css/site.css" type="text/css" /> |
| <script type="text/javascript" src="../js/jquery.min.js"></script> |
| <script type="text/javascript" src="../js/bootstrap.min.js"></script> |
| <script type="text/javascript" src="../js/prettify.min.js"></script> |
| <script type="text/javascript" src="../js/site.js"></script> |
| <meta name="author" content="Nicko Cadell" /> |
| <meta name="Date-Revision-yyyymmdd" content="20170428" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| <meta name="keywords" content="log4net examples, log4net" /> |
| </head> |
| <body class="composite"> |
| <a href="https://logging.apache.org/"> |
| <img class="logo-left" src="../images/ls-logo.jpg" alt="Apache logging services logo" /> |
| </a> |
| <!--img class="logo-right" src="../images/logo.png" alt="Apache log4net logo" /--> |
| <div class="clear"></div> |
| |
| <div class="navbar"> |
| <div class="navbar-inner"> |
| <div class="container-fluid"> |
| <a class="brand" href="http://logging.apache.org/log4net/">Apache log4net ™</a> |
| <ul class="nav"> |
| <li> |
| |
| |
| <a href="https://wiki.apache.org/logging" class="external" target="_blank" title="Logging Wiki">Logging Wiki</a> |
| </li> |
| <li> |
| |
| |
| <a href="https://www.apache.org/" class="external" target="_blank" title="Apache">Apache</a> |
| </li> |
| <li> |
| |
| |
| <a href="https://logging.apache.org/" class="external" target="_blank" title="Logging Services">Logging Services</a> |
| </li> |
| <li> |
| |
| |
| <a href="https://github.com/apache/logging-log4net/" class="external" target="_blank" title="GitHub">GitHub</a> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| |
| <div class="container-fluid"> |
| <table class="layout-table"> |
| <tr> |
| <td class="sidebar"> |
| <div class="well sidebar-nav"> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-home"></i>Apache log4net</li> |
| <li class="none"> |
| <a href="../index.html" title="About">About</a> |
| </li> |
| <li class="none"> |
| <a href="../download_log4net.cgi" title="Download">Download</a> |
| </li> |
| <li class="none"> |
| <a href="../release/release-notes.html" title="Release Notes">Release Notes</a> |
| </li> |
| <li class="none"> |
| <a href="../license.html" title="License">License</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-file"></i>Documentation</li> |
| <li class="none"> |
| <a href="../release/features.html" title="Features">Features</a> |
| </li> |
| <li class="none"> |
| <a href="../release/framework-support.html" title="Supported Frameworks">Supported Frameworks</a> |
| </li> |
| <li class="none active"> |
| <a href="../release/example-apps.html" title="Example Apps">Example Apps</a> |
| </li> |
| <li class="none"> |
| <a href="../release/config-examples.html" title="Config Examples">Config Examples</a> |
| </li> |
| <li class="none"> |
| <a href="../release/building.html" title="Building">Building</a> |
| </li> |
| <li class="none"> |
| <a href="../release/faq.html" title="FAQ">FAQ</a> |
| </li> |
| <li class="none"> |
| <a href="../release/howto/index.html" title="How Tos">How Tos</a> |
| </li> |
| <li class="none"> |
| <a href="../release/sdk/index.html" title="SDK Reference">SDK Reference</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-book"></i>Manual</li> |
| <li class="none"> |
| <a href="../release/manual/introduction.html" title="Introduction">Introduction</a> |
| </li> |
| <li class="none"> |
| <a href="../release/manual/configuration.html" title="Configuration">Configuration</a> |
| </li> |
| <li class="none"> |
| <a href="../release/manual/contexts.html" title="Contexts">Contexts</a> |
| </li> |
| <li class="none"> |
| <a href="../release/manual/plugins.html" title="Plugins">Plugins</a> |
| </li> |
| <li class="none"> |
| <a href="../release/manual/repositories.html" title="Repositories">Repositories</a> |
| </li> |
| <li class="none"> |
| <a href="../release/manual/internals.html" title="Internals">Internals</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-pencil"></i>For Contributors</li> |
| <li class="none"> |
| <a href="../mail-lists.html" title="Mailing Lists">Mailing Lists</a> |
| </li> |
| <li class="none"> |
| <a href="../issue-tracking.html" title="Issue Tracking">Issue Tracking</a> |
| </li> |
| <li class="none"> |
| <a href="../source-repository.html" title="Repository">Repository</a> |
| </li> |
| <li class="none"> |
| <a href="../integration.html" title="Continuous Integration">Continuous Integration</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-cog"></i>Project Reports</li> |
| <li class="none"> |
| <a href="../rat-report.html" title="RAT Report">RAT Report</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-info-sign"></i>Apache</li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/" class="external" target="_blank" title="Home">Home</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/licenses/" class="external" target="_blank" title="License">License</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/foundation/sponsorship.html" class="external" target="_blank" title="Sponsorship">Sponsorship</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/foundation/thanks.html" class="external" target="_blank" title="Thanks">Thanks</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/security/" class="external" target="_blank" title="Security">Security</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apachecon.com" class="external" target="_blank" title="Conferences">Conferences</a> |
| </li> |
| </ul> |
| </div> |
| <div id="poweredBy"> |
| <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"> |
| <img class="poweredBy" alt="Built by Maven" src="../images/maven-feather.png" /> |
| </a> |
| </div> |
| </td> |
| <td class="content"> |
| <!-- Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to you under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. --> |
| |
| |
| <a name="main"></a> |
| <div class="section" id="main"> |
| <h2><a name="Apache_log4net_Examples"></a>Apache log4net™ Examples</h2> |
| |
| <a name="overview"></a> |
| <div class="section" id="overview"> |
| <h2><a name="Overview"></a>Overview</h2> |
| |
| <p> |
| <b>The following examples are only available in the log4net source download, not |
| on-line. To obtain the examples <a href="../download_log4net.cgi">download</a> the log4net source release. |
| </b> |
| </p> |
| </div> |
| |
| <a name="building"></a> |
| <div class="section" id="building"> |
| <h2><a name="Building_Examples"></a>Building Examples</h2> |
| <a name="building-1"></a> |
| <div class="section" id="building-1"> |
| <h2><a name="Building_An_Example"></a>Building An Example</h2> |
| |
| <p> |
| A single example can be build by running <span class="code">nant</span> from |
| the example directory. |
| </p> |
| |
| <p> |
| For example running <span class="code">nant</span> in the |
| <span class="code">examples\net\1.0\Tutorials\ConsoleApp\cs</span> directory |
| will build the C# version of the Microsoft® .NET 1.0 ConsoleApp example. |
| </p> |
| |
| <p> |
| <span class="code">nant</span> can be run in any directory containing a |
| <span class="code">nant.build</span> file. The typical behavior of the build file |
| is to build all projects under the current directory. |
| </p> |
| |
| <p> |
| For example running <span class="code">nant</span> in the |
| <span class="code">examples\net\1.1</span> directory |
| will build all the examples for the .NET 1.1 platform. |
| </p> |
| </div> |
| |
| <a name="building-all"></a> |
| <div class="section" id="building-all"> |
| <h2><a name="Building_All_Examples"></a>Building All Examples</h2> |
| |
| <p> |
| To build all the examples either run <span class="code">nant</span> in the |
| <span class="code">examples</span> directory or you can specify the |
| <span class="code">compile-examples</span> target to the main log4net nant build. |
| </p> |
| </div> |
| |
| <a name="building-vsnet"></a> |
| <div class="section" id="building-vsnet"> |
| <h2><a name="Visual_Studio_.NET"></a>Visual Studio .NET</h2> |
| |
| <p> |
| There are Visual Studio .NET 2002 project files for the .NET 1.0 framework. |
| The solution files for C# and VB are in the examples\net\1.0 |
| folder. |
| </p> |
| |
| <p> |
| For the Managed C++ project there is a Visual Studio .NET 2003 project file |
| in the examples\net\1.1 folder. |
| </p> |
| </div> |
| </div> |
| |
| <a name="examples"></a> |
| <div class="section" id="examples"> |
| <h2><a name="Examples"></a>Examples</h2> |
| |
| <a name="consoleapp"></a> |
| <div class="section" id="consoleapp"> |
| <h2><a name="Tutorial_-_ConsoleApp"></a>Tutorial - ConsoleApp</h2> |
| |
| <p> |
| ConsoleApp shows how to write a simple console application that initializes |
| logging and logs various events. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>MONO 1.0</b>: |
| C# |
| </li> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C#, |
| VB |
| </li> |
| |
| <li> |
| <b>.NET 1.1</b>: |
| C++, |
| JScript.NET |
| </li> |
| |
| <li> |
| <b>.NET Compact Framework 1.0</b>: |
| C#, |
| VB |
| </li> |
| |
| <li> |
| <b>SSCLI 1.0</b>: |
| JScript.NET |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">ConsoleApp.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="webapp"></a> |
| <div class="section" id="webapp"> |
| <h2><a name="Tutorial_-_WebApp"></a>Tutorial - WebApp</h2> |
| |
| <p> |
| ConsoleApp shows how to write a simple ASP.NET web application that initializes |
| logging and logs various events. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C#, |
| VB |
| </li> |
| </ul> |
| |
| <p> |
| To run this example you need to have an ASP.NET container application to |
| host the web application, for example IIS. In IIS create a new virtual |
| directory pointing to the WebApp src directory. Configure IIS to recognize |
| this virtual directory as an application. Open up a web browser, navigate to |
| the virtual directory and to the <span class="code">WebForm1.aspx</span> page within it. |
| </p> |
| </div> |
| |
| <a name="remotingclient"></a> |
| <div class="section" id="remotingclient"> |
| <h2><a name="Remoting_-_RemotingClient"></a>Remoting - RemotingClient</h2> |
| |
| <p> |
| The RemotingClient application is a simple console application that configures |
| log4net with the RemotingAppender. This appender will attempt to deliver the |
| logging events to a remoting listener. This example should be run in conjunction |
| with the RemotingServer. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">RemotingClient.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="remotingserver"></a> |
| <div class="section" id="remotingserver"> |
| <h2><a name="Remoting_-_RemotingServer"></a>Remoting - RemotingServer</h2> |
| |
| <p> |
| The RemotingServer application is a simple console application that listens for |
| logging events from a remote RemotingAppender and then logs them through the |
| local log4net instance. This example should be run in conjunction |
| with the RemotingClient. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">RemotingServer.exe</span> from the build output directory. |
| While this process is running execute the <span class="code">RemotingClient.exe</span> program on |
| the same machine. The logging events from the client are transferred to the server. |
| </p> |
| </div> |
| |
| <a name="rep-simple"></a> |
| <div class="section" id="rep-simple"> |
| <h2><a name="Repository_-_SimpleModule"></a>Repository - SimpleModule</h2> |
| |
| <p> |
| The SimpleModule is a class library that is intended to be used as part of |
| the SimpleApp example, |
| This class library uses the <span class="code">log4net.Config.Repository</span> |
| attribute to create a separate configuration space from other assemblies. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>MONO 1.0</b>: |
| C# |
| </li> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C#, |
| VB |
| </li> |
| |
| <li> |
| <b>.NET 1.1</b>: |
| JScript.NET |
| </li> |
| |
| <li> |
| <b>SSCLI 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| This library is intended to be used as part of the SimpleApp example. |
| </p> |
| </div> |
| |
| <a name="rep-shared"></a> |
| <div class="section" id="rep-shared"> |
| <h2><a name="Repository_-_SharedModule"></a>Repository - SharedModule</h2> |
| |
| <p> |
| The SharedModule is a class library that is intended to be used as part of |
| the SimpleApp example, |
| This class library uses log4net but does not attempt to configure logging. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>MONO 1.0</b>: |
| C# |
| </li> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C#, |
| VB |
| </li> |
| |
| <li> |
| <b>.NET 1.1</b>: |
| JScript.NET |
| </li> |
| |
| <li> |
| <b>SSCLI 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| This library is intended to be used as part of the SimpleApp example. |
| </p> |
| </div> |
| |
| <a name="rep-app"></a> |
| <div class="section" id="rep-app"> |
| <h2><a name="Repository_-_SimpleApp"></a>Repository - SimpleApp</h2> |
| |
| <p> |
| The SimpleApp example uses the SimpleModule and SharedModule to demonstrate |
| the ways in which multiple assemblies within the same process may be |
| separately configured. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>MONO 1.0</b>: |
| C# |
| </li> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C#, |
| VB |
| </li> |
| |
| <li> |
| <b>.NET 1.1</b>: |
| JScript.NET |
| </li> |
| |
| <li> |
| <b>SSCLI 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">SimpleApp.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="eventidlogapp"></a> |
| <div class="section" id="eventidlogapp"> |
| <h2><a name="Extensibility_-_EventIDLogApp"></a>Extensibility - EventIDLogApp</h2> |
| |
| <p> |
| The EventIDLogApp example demonstrates using the log4net.Ext.EventID extension. |
| The extension needs to be built separately from the |
| <span class="code">extensions\net\1.0\log4net.Ext.EventID</span> directory. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">EventIDLogApp.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="tracelogapp"></a> |
| <div class="section" id="tracelogapp"> |
| <h2><a name="Extensibility_-_TraceLogApp"></a>Extensibility - TraceLogApp</h2> |
| |
| <p> |
| The TraceLogApp example demonstrates using the log4net.Ext.Trace extension. |
| The extension needs to be built separately from the |
| <span class="code">extensions\net\1.0\log4net.Ext.Trace</span> directory. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">TraceLogApp.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="sampleappenders"></a> |
| <div class="section" id="sampleappenders"> |
| <h2><a name="SampleAppenders"></a>SampleAppenders</h2> |
| |
| <p> |
| This project includes the following example appenders. |
| </p> |
| |
| <ul> |
| |
| <li> |
| AsyncAppender |
| </li> |
| |
| <li> |
| FastDbAppender |
| </li> |
| |
| <li> |
| FireEventAppender |
| </li> |
| |
| <li> |
| MessageBoxAppender |
| </li> |
| |
| <li> |
| MessageObjectExpanderAppender |
| </li> |
| |
| <li> |
| MsmqAppender |
| </li> |
| |
| <li> |
| PatternFileAppender |
| </li> |
| |
| <li> |
| SimpleSmtpAppender |
| </li> |
| </ul> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">SampleAppendersApp.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="samplelayouts"></a> |
| <div class="section" id="samplelayouts"> |
| <h2><a name="SampleLayouts"></a>SampleLayouts</h2> |
| |
| <p> |
| This project includes the following example layouts. |
| </p> |
| |
| <ul> |
| |
| <li> |
| ForwardingLayout |
| </li> |
| |
| <li> |
| LineWrappingLayout |
| </li> |
| </ul> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| To run this example execute <span class="code">SampleLayoutsApp.exe</span> from the build output directory. |
| </p> |
| </div> |
| |
| <a name="perf-notlogging"></a> |
| <div class="section" id="perf-notlogging"> |
| <h2><a name="Performance_-_NotLogging"></a>Performance - NotLogging</h2> |
| |
| <p> |
| The NotLogging example benchmarks the performance of log4net logging statements in |
| user code in various scenarios including when logging is disabled. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>MONO 1.0</b>: |
| C# |
| </li> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C#, |
| VB |
| </li> |
| </ul> |
| |
| <p> |
| </p> |
| </div> |
| |
| <a name="wmiappender"></a> |
| <div class="section" id="wmiappender"> |
| <h2><a name="WmiAppender"></a>WmiAppender</h2> |
| |
| <p> |
| The WmiAppender sample shows an example appender that fires events through |
| Windows Management Instrumentation. |
| </p> |
| |
| <p> |
| This example is available for the following platforms and languages. If a version |
| is not available for your chosen platform and language combination then select the |
| nearest platform for the appropriate language. |
| </p> |
| |
| <ul> |
| |
| <li> |
| <b>.NET 1.0</b>: |
| C# |
| </li> |
| </ul> |
| |
| <p> |
| </p> |
| </div> |
| |
| </div> |
| |
| </div> |
| |
| |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="footer"> |
| <p>Copyright © 2004-2017 <a class="external" href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.</p> |
| <p>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.</p> |
| <p>Site powered by <a class="external" href="http://getbootstrap.com/">Twitter Bootstrap</a>. Icons from <a class="external" href="http://glyphicons.com/">Glyphicons Free</a>.</p> |
| </div> |
| </div> |
| </body> |
| </html> |