Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share nlog config with multiple projects and the proper threadsafe way to all write to the same log file?

Tags:

c#

nlog

My program consists of a single EXE and 6 DLLs (and of course everyone references everyone), I currently have a crude static logging class (Logger) which is in its own DLL (Logger.dll) which I add as a reference to each of my projects and use ... but instead of re-inventing the wheel I was looking to replace this with nLog.

Problem is I can't seem to figure out how all my projects can share the same nLog config file (I want everything logging to the SAME file and I do not want to define a config file per project).

  1. is there a way to have a single config file for all my projects?
  2. is this safe to do? will nLog in each project accessing the same file not cause contention issues? does nLog already handle this correctly?

Or would it simply be best for me to wrap nLog in my static Logger.dll (odd to do but would work also) and keep doing things like I do today in my application?

Thanks,

like image 993
JSchwartz Avatar asked Dec 13 '12 06:12

JSchwartz


People also ask

How do you use NLog for multiple projects in the same solution?

How do you use NLog for multiple projects in the same solution? If you want to log in other projects within the solution, just reference NLog. dll directly in each of the projects and use it. But now you only need to configure NLog in your main application.

What can be configured with this NLog config file?

The following types can be configured: Targets - the destinations of a logevent, e.g. file, database, console. Layout - the layout e.g. json, csv, plain-text (default) Layout renderers - the template markers, e.g. ${message}, ${exception}, ${date}

Where does NLog write to by default?

Version 7. By default, the web. nlog file can be found at: C:\Program Files (x86)\Pleasant Solutions\Pleasant Password Server\www\web.


1 Answers

NLog should handle what you want to . The NLog.config file is applied at the application (EXE) level. So, if you configure NLog in the 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 retrieve a logger from NLog, will return a logger that has been configured according to the EXE-level NLog.config file.

like image 87
wageoghe Avatar answered Sep 26 '22 06:09

wageoghe