使NLog.config文件从(d:\ dev)而不是"\ bin \ debug \"加载文件. [英] make NLog.config file load the file from (d:\dev) instead of "\bin\debug\"
问题描述
我将Nlog用于特定DLL中的日志记录目的.然后,该DLL在另一个应用程序中使用(使用 System.Reflection.Assembly.LoadFrom(path + a.dll)
动态加载).我将Nlog.dll和Nlog.config文件手动放置在Path文件夹中,该应用程序可以正常执行,但不会记录任何消息.
I used Nlog for logging purpose in a particular DLL. The DLL is then used in another application (it is loaded dynamically using System.Reflection.Assembly.LoadFrom(path + a.dll)
). I manually placed Nlog.dll and Nlog.config files in Path folder and the application executes properly but it does not log any messages.
但是,当我继续将Nlog.config文件手动放置在应用程序目录( \ bin \ debug \
)中时,它是日志消息.
However, when I go ahead and place the Nlog.config file manually in application directory (\bin\debug\
) is logs messages.
有人可以让我知道如何将Nlog.Config的搜索位置指向除 \ bin \ debug \
之外的其他目录( d:\ dev
).
Can someone let me know how to point the search location for Nlog.Config to a different directory (d:\dev
) other than \bin\debug\
.
推荐答案
下面是我如何更改Nlog的配置,使其指向执行程序文件夹中存在的Nlog.config文件.
Below is how i changed configuration of Nlog to point to Nlog.config file present in Executing Assembly's folder.
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\NLog.config", true);
这篇关于使NLog.config文件从(d:\ dev)而不是"\ bin \ debug \"加载文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!