====== Log4net Setup ======
===== AssemblyInfo.cs =====
// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
===== App.config =====
This file is named 'app.config' in the source. Visual Studio seems to rename this to 'ApplicationName.exe.config' when it is copied to the bin directory during compilation.
To roll the log files, use something like this:
To specify only certain loggers:
...
To remove certain loggers:
...
...
To switch off all logging:
===== Logger.cs =====
namespace FooBar
{
using log4net;
internal static class Logger
{
private static ILog _general;
internal static ILog General
{
get
{
if (_general == null)
{
_general = LogManager.GetLogger("General");
// Ensure the logger gets configured.
log4net.Config.XmlConfigurator.Configure();
}
return _general;
}
}
}
}
===== Levels =====
* Off
* Fatal
* Error
* Warn
* Info
* Debug
* All
{{tag>log4net reference}}