Log4net Not Creating Log File

后端 未结 6 998
栀梦
栀梦 2020-12-15 03:34

I\'m getting an error on a program that has log4net configured, but no log file is being created. I\'m certain the logging is set up in the program because other users have

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 04:08

    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!!!

提交回复
热议问题