How configure log4net for a c# Windows service

前端 未结 2 468
情深已故
情深已故 2021-02-02 00:36

I have a windows service where the app.config file and the log4net.config files are seperate. The logging is not working.

In my app.config file, I have the following in

2条回答
  •  难免孤独
    2021-02-02 01:16

    For Windows service the current directory is Windows\system32 -- and XmlConfigurator.Configure() uses FileInfo which treats relative paths relative to the current directory. So log4net is looking for its config file in Windows\system32.

    XmlConfiguratorAttribute on the other hand uses application's BaseDirectory, this is why it always works.

    Alternatively, you can do following before calling XmlConfigurator.Configure() :

    System.IO.Directory.SetCurrentDirectory (AppDomain.CurrentDomain.BaseDirectory);
    

提交回复
热议问题