1. Create a config file calls 'log4net.config', and put it in 'c:\log\'
2. Create a Class Library Project call 'MyLogging', add a reference for log4net.dll. Add a new Class calls 'Logger.cs'.
public class Logger { private const string LOG4NET_CONFIG_FILE = "C:\\log\\log4net.config"; private log4net.ILog logger; private Logger() { log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(LOG4NET_CONFIG_FILE)); } public Logger(string loggerName) : this() { logger = log4net.LogManager.GetLogger(loggerName); } public Logger(Type type) : this() { logger = log4net.LogManager.GetLogger(type); } #region ILog Members public void Debug(object message) { if (logger.IsDebugEnabled) logger.Debug(message); } public void Debug(object message, Exception ex) { if (logger.IsDebugEnabled) logger.Debug(message, ex); } public void Info(object message) { if (logger.IsInfoEnabled) logger.Info(message); } public void Info(object message, Exception ex) { if (logger.IsInfoEnabled) logger.Info(message); } public void Warn(object message) { if (logger.IsWarnEnabled) logger.Warn(message); } public void Warn(object message, Exception ex) { if (logger.IsWarnEnabled) logger.Warn(message, ex); } public void Error(object message) { if (logger.IsErrorEnabled) logger.Error(message); } public void Error(object message, Exception ex) { if (logger.IsErrorEnabled) logger.Error(message, ex); } public void Fatal(object message) { if (logger.IsFatalEnabled) logger.Fatal(message); } public void Fatal(object message, Exception ex) { if (logger.IsFatalEnabled) logger.Fatal(message, ex); } #endregion }