问题
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).
- is there a way to have a single config file for all my projects?
- 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