1

I'm writing a Windows Service, and thought it better to create a new Logger in each call of OnStart, vs. in the service constructor. That way, I hope changes to the config file will become effective when the service is restarted, without having to somehow restart the process and all the hassles with that.

Then it occurred to me that NLog might only read the file once, when it initialises LogManager or something, and my precaution is futile.

ProfK
  • 49,207
  • 121
  • 399
  • 775

1 Answers1

1

If you use the configuration file (nlog.config), you could enable autoReload.

<nlog autoReload="true">
   ...
</nlog>

If enabled and there is a change in the nlog.config, the configuration will be automatically reloaded without a service restart. See Automatic reconfiguration.

If you configure NLog problematically (so without the nlog.config), then you need to call LogManager.ReconfigExistingLoggers after a change in the configuration.

and thought it better to create a new Logger in each call of OnStart, vs. in the service ctor.

For both cases it doesn't matter when the new Logger is created.

Julian
  • 33,915
  • 22
  • 119
  • 174