Logging: Log4Net – Part I

By DimitriC at April 26, 2010 09:01
Filed Under: tools & Utilities

This tool gives you the possibility to log whatever you want (not just errors or warnings but also informational logging) to whatever output target you want (database, flat-file, console window, Trace-window,…).  It’s an open-source tool (ported from log4j) and relatively simple to use so you can use it in all of your projects in which you want to use logging (from small/simple applications to huge/complex ones).

Key Features:

  • - Support for multiple frameworks
  • - Output to multiple logging targets
  • - Hierarchical logging architecture
  • - XML Configuration
  • - Dynamic Configuration
  • - Logging Context
  • - Proven architecture
  • - Modular and extensible design
  • - High performance with flexibility

  •  

     

    For a complete list of the possible output streams, I refer to the log4net feature-page.

    The first point on the key-features-list is interesting. There is not only support for the Microsoft .NET framework 1.0/1.1/2.0/… and it’s variations (.NET Compact Framework, SSCLI 1.0), but also for Mono 1.0/2.0. The website doesn’t mention anything about any Microsoft .NET framework higher than 2.0, but I’m using it in my .NET framework 3.5 project without any issues (since 3.5 is just 2.0 with some extra goodies :) ). For the full list of supported frameworks and framework specific notes, I refer to the log4net Supported Frameworks-page.

 

Concerning the recently released .NET 4 Framework and Visual Studio 2010 there were some minor issues reported. Since there aren’t that many releases of Log4Net, you can always download the source code and compile it yourself.

 

The main issue that i see reported today is that the compiler throws an error saying the log4net assembly reference could not be found:

The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)

 

Here you should check you should set the Target Framework to “.Net Framework 4” in your project’s properties.

  • Log4Net can be configured in 2 ways: you can do it in code (programmatically) or you can do it using a configuration file. The second one is most interesting since it will allow you to make modifications to the configuration without having to recompile your code. And it will also allow you to change the configuration while your program is running. In the following parts, the emphasis will be on the configuration by configuration file.

    Get log4net!

Pingbacks and trackbacks (1)+

Comments are closed