We are using log4net and want to specify it\'s configuration in an external config file (as we have done with other sections). To do this we have changed the log4net section
Assuming you had an external config file called log4net.config that is copied to your deploy directory you can configure it like so:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Reflection;
using log4net;
namespace MyAppNamespace {
static class Program {
//declare it as static and public so all classes in the project can access it
//like so: Program.log.Error("got an error");
public static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
///
/// The main entry point for the application.
///
[STAThread]
static void Main() {
//configure it to use external file
log4net.Config.XmlConfigurator.Configure(new Uri(Application.StartupPath + "\\log4net.config"));
//use it
log.Debug("############# STARING APPLICATION #################");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
}
}
}