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

混江龙づ霸主 提交于 2021-02-07 12:38:50

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/13854426/share-nlog-config-with-multiple-projects-and-the-proper-threadsafe-way-to-all-wr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!