Initialising log4net logging for Asp.Net web app

Some snippet below:

protected void Application_Start(object sender, EventArgs e)
{
XmlConfigurator.Configure();

log4net.Repository.ILoggerRepository repo = LogManager.GetRepository();
foreach (log4net.Appender.IAppender appender in repo.GetAppenders())
{
if (appender.Name.CompareTo(“RollingFileAppender”) == 0 && appender is log4net.Appender.RollingFileAppender)
{
var appndr = appender as log4net.Appender.RollingFileAppender;
string logPath = “MyApplication.log”;
appndr.File = logPath;
appndr.ActivateOptions();
}
}

logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

var configSource = new XmlConfigurationSource(ActiveRecordConfigStream);

Assembly assy = typeof([ParentAssembly]).Assembly;
ActiveRecordStarter.Initialize(configSource, assy.GetTypes());

logger.Info(“My Application Starting…”);
}

One thought on “Initialising log4net logging for Asp.Net web app

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.