问题
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