Sharing nlog configuration with multiple projects and proper thread safe way to write to the same log file?

My program consists of one EXE library and 6 DLLs (and, of course, everyone refers to everyone), currently I have a rough static registration class (Logger), which is in my own DLL (Logger.dll), which I add to as a link to each of my projects and use ... but instead of reinventing the wheel, I was looking to replace this with nLog.

The problem is that I cannot understand how all my projects can share the same nLog configuration file (I want everything to be logged to a SAME file, and I don't want to define a configuration file for each project).

  • Is there a way to have one configuration file for all my projects?
  • Is it safe to do this? Will nLog in each project access a single file without causing conflicts? Does nlog already handle this correctly?

Or would I just be better off wrapping nLog in my static Logger.dll file (odd, but it will work too) and continue to do things like today in my application?

Thanks,

+8
c # nlog
source share
1 answer

NLog should process what you want. The NLog.config file is applied at the application level (EXE). Thus, if you configure NLog in NLog.config, the configuration will be read when the application starts. All classes, whether in the EXE or in one of your DLLs, when they extract the registrar from NLog, return the log that was configured according to the NLog.config file at the EXE level.

+7
source share

All Articles