Log4net Not Creating Log File

Give the following code in your application before you put your logging code:

log4net.Config.XmlConfigurator.Configure();

You can define it in Global.asax:

void Application_Start(object sender, EventArgs e) 
{
    // Code that runs on application startup

    // Initialize log4net.
    log4net.Config.XmlConfigurator.Configure();
}

You can also add the following line as Kevin advised (either mentioning your config file name or not):

[assembly: log4net.Config.XmlConfigurator]

or

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]

Hope it helps!!!

Leave a Comment