make NLog.config file load the file from (d:\dev) instead of "\bin\debug\"

rookie_developer picture rookie_developer · Apr 11, 2013 · Viewed 23.3k times · Source

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.

However, when I go ahead and place the Nlog.config file manually in application directory (\bin\debug\) is logs messages.

Can someone let me know how to point the search location for Nlog.Config to a different directory (d:\dev) other than \bin\debug\.

Answer

rookie_developer picture rookie_developer · Apr 17, 2013

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);