Nlog config file priority

梦想的初衷 提交于 2019-12-11 10:28:15

问题


So, I have library shared among more executables. If I understand properly, I cannot attach config to library directly like library.dll.nlog, but I have to use config per exe or use nlog.config for global settings. (It's ok to log from more places into single log.)

Here we come with few more executables that don't use this dll and it is required to log into different log files, so, I can use config per exe like app.exe.nlog. It works flawlessly, until placed in directory with nlog.config file.

Based on https://github.com/nlog/NLog/wiki/Configuration-file I would expect that settings will be loaded by priority (so first dedicated to exe, then global), when config is found, it's used.

So, I am doing anything wrong or is there some flaw in order of config processing?


回答1:


Unfortunately this is a in NLog 4 bug and there is a change waiting: https://github.com/NLog/NLog/pull/959, as it's a breaking change, it has to wait for NLog 5.

If you need to know in which order NLog it checking it files, you could call:

var paths = LogManager.LogFactory.GetCandidateConfigFilePaths().ToList();

You could also override the current used paths with SetCandidateConfigFilePaths:

LogManager.LogFactory.SetCandidateConfigFilePaths(new[] { "c://temp/my-nlog.config" });


来源:https://stackoverflow.com/questions/49894580/nlog-config-file-priority

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