I have log4net working with an external config file, by telling my app config where to find the config file and then calling XmlConfigurator.Configure() when the app starts.
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
...
<log4net configSource="Log4Net.config" />
This works, but I now want to watch for changes,According to the documentation I should be able to use the assembly attribute to achieve this, which also means I don’t need to call XmlConfigurator.Configure() any more. So, I add this to the AssemblyInfo.cs for the main app (and also for the project it references):
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Trouble is, this does nothing at all. If I remove the call to XmlConfigurator.Configure(), then the logging doesn’t work – no logging is initiated. Those attributes don’t seem to make a difference. So, I can’t get watching the file working at all.
Can anyone advise?
Sussed it.
It was because the first logging message came from another assembly. As the log4net docs say: