log4net only works when XmlConfigurator.Configure() is called

前端 未结 2 874
攒了一身酷
攒了一身酷 2020-12-03 10:19

I understand that this question has been asked several times, but unfortunately, I haven\'t been able to get my logging configuration working. I have to be making some very

相关标签:
2条回答
  • 2020-12-03 11:19

    You do not need to call the XmlConfigurator manually if you use:

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

    However you have to add the tag to all your dlls (all assambly.cs files).

    0 讨论(0)
  • 2020-12-03 11:20

    I have faced exactly the same issue. As you rightly point out, you should not need to explicitly call XmlConfigurator when you include the line in your AssemblyInfo.cs. The problem comes when the first use of log4net is in an assebmly that doesn't have that line. In my case I was using the Topshelf.Log4Net NuGet package, and the first log line that my application logged was through that.

    You could just log a line early in your app or if you don't need to log anything do what I did and add the following at the entry point of the application

    LogManager.GetLogger(typeof(Program));
    
    0 讨论(0)
提交回复
热议问题