0

.Net applications are set up so that multiple instances of the same program will be (re)using the same application config (.exe.config - app.config in Visual Studio).

In our scenario we need to run each of the instances with their own .exe.config. This is not something that .Net is made to do "out of the box". However this nice little wrapper does the trick for us: https://stackoverflow.com/a/6151688/95008

This worked fine for us, until we realized that NLog does not seem to respect the app-config change. We are adding a config-section in the .exe.config for NLog which should make it possible each instance to log with different rules and targets to different locations.

But, it seems that NLog is not respecting the app-config changes. My guess is that it internally is not asking via the AppSettings API for its config-section, instead perhaps using code to manually look up the .exe.config and the config-section within it.

So, three alternatives it seems:

  1. Look into NLog changing the code for this in a future release (given that this indeed is the issue). I will be posting an issue with the project for Update: Link to NLog issue.
  2. Loading the configuration manually, either from the section of the .exe.config or from a specific nlog.config file (maybe given via a setting in the .exe.config). But, how do we do this effectively, so that any loggers created are based on the configs manually loaded?
  3. Maybe there is another solution for this?
Spiralis
  • 3,232
  • 2
  • 39
  • 53
  • Can't you do this: https://stackoverflow.com/questions/37687546/how-to-force-reload-of-nlog-configuration-file ? – rene Dec 29 '17 at 13:37
  • Thanks. Maybe. I was just looking at that myself, but I was hoping that there would be a simpler solution. – Spiralis Dec 29 '17 at 13:38
  • @rene Actually, the answer there doesn't seem to be exactly what we are looking for, as just reloading will still just try the same .exe.config. But, one of the comments look promising: `NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(NLogConfigFile_Dst, true); NLog.LogManager.ReconfigExistingLoggers();` – Spiralis Dec 29 '17 at 13:46

1 Answers1

0

My guess is that it internally is not asking via the AppSettings API for its config-section, instead perhaps using code to manually look up the .exe.config and the config-section within it.

That's correct, as NLog is using the same code for the NLog's config, whether it's in web.config or in nlog.config

Reloading the config is easy in code, just do:

NLog.LogManager.Configuration = NLog.LogManager.Configuration.Reload();

and if there are loggers made before the config is reloaded,

NLog.LogManager.ReconfigExistingLoggers()
Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
Julian
  • 33,915
  • 22
  • 119
  • 174
  • Thanks. But, this will only trigger a reload, right? It will not understand that the app.config is not the one located next to the binary, afaict? – Spiralis Dec 29 '17 at 16:09