# log4net Examples

## Contents

Overview
Building Examples
Building An Example
Building All Examples
Visual Studio .NET 2002
Examples
Tutorial - ConsoleApp
Tutorial - WebApp
Remoting - RemotingClient
Remoting - RemotingServer
Repository - SimpleModule
Repository - SharedModule
Repository - SimpleApp
Extensibility - EventIDLogApp
Extensibility - TraceLogApp
SampleAppenders
Performance - NotLogging

## Overview

## Building Examples

### Building An Example

A single example can be build by running nant from the example directory.

For example running nant in the examples\net\1.0\Tutorials\ConsoleApp\cs directory will build the C# version of the .NET 1.0 ConsoleApp example.

nant can be run in any directory containing a nant.build file. The typical behaviour of the build file is to build all projects under the current directory.

For example running nant in the examples\net\1.1 directory will build all the examples for the .NET 1.1 platform.

### Building All Examples

To build all the examples either run nant in the examples directory or you can specify the compile-examples target to the main log4net nant build.

### Visual Studio .NET 2002

There are Visual Studio .NET 2002 project files for the .NET 1.0 framework. The solution files for C++, C# and VB are in the examples\net\1.0 folder.

## Examples

### Tutorial - ConsoleApp

ConsoleApp shows how to write a simple console application that initializes logging and logs various events.

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.

- MONO 1.0: C#
- .NET 1.0: C++, C#, VB
- .NET 1.1: JavaScript
- .NET Compact Framework 1.0: C#, VB
- SSCLI 1.0: JavaScript

To run this example execute the ConsoleApp.exe from the build output directory.

### Tutorial - WebApp

ConsoleApp shows how to write a simple ASP.NET web application that initializes logging and logs various events.

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.

- .NET 1.0: C#, VB

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 webrowser, navigate to the virtual directory and to the WebForm1.aspx page within it.

### Remoting - RemotingClient

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.

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.

- .NET 1.0: C#

To run this example execute the RemotingClient.exe from the build output directory.

### Remoting - RemotingServer

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.

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.

- .NET 1.0: C#

To run this example execute the RemotingServer.exe from the build output directory. While this process is running execute the RemotingClient.exe program on the same machine. The logging events from the client are transferred to the server.

### Repository - SimpleModule

The SimpleModule is a class library that is intended to be used as part of the SimpleApp example, This class library uses the log4net.Config.Repository attribute to create a separate configuration space from other assemblies.

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.

- MONO 1.0: C#
- .NET 1.0: C#, VB
- .NET 1.1: JavaScript
- SSCLI 1.0: C#

This library is intended to be used as part of the SimpleApp example.

### Repository - SharedModule

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.

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.

- MONO 1.0: C#
- .NET 1.0: C#, VB
- .NET 1.1: JavaScript
- SSCLI 1.0: C#

This library is intended to be used as part of the SimpleApp example.

### Repository - SimpleApp

The SimpleApp example uses the SimpleModule and SharedModule to demonstrate the ways in which multiple assemblies within the same process may be separately configured.

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.

- MONO 1.0: C#
- .NET 1.0: C#, VB
- .NET 1.1: JavaScript
- SSCLI 1.0: C#

To run this example execute the SimpleApp.exe from the build output directory.

### Extensibility - EventIDLogApp

The EventIDLogApp example demonstrates using the log4net.Ext.EventID extension. The extension needs to be built separately from the extensions\net\1.0\log4net.Ext.EventID directory.

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.

- .NET 1.0: C#

To run this example execute the EventIDLogApp.exe from the build output directory.

### Extensibility - TraceLogApp

The TraceLogApp example demonstrates using the log4net.Ext.Trace extension. The extension needs to be built separately from the extensions\net\1.0\log4net.Ext.Trace directory.

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.

- .NET 1.0: C#

To run this example execute the TraceLogApp.exe from the build output directory.

### SampleAppenders

This project includes the following example appenders.

- FireEventAppender
- MessageBoxAppender
- MessageObjectExpanderAppender
- SimpleSmtpAppender

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.

- .NET 1.0: C#

To run this example execute the SampleAppendersApp.exe from the build output directory.

### Performance - NotLogging

The NotLogging example benchmarks the performance of log4net logging statements in user code in various scenarios including when logging is disabled.

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.

- MONO 1.0: C#
- .NET 1.0: C#, VB

Copyright © 2004-2005, Apache Software Foundation