I did it this way e.g. in the Main function or at the beginning of my program:
// change the log file specified in the NLog config file
// supposing that a target "file" as file target in config file
FileTarget target = LogManager.Configuration.FindTargetByName("file") as FileTarget;
String logfile = "somepath" + "/some_name.txt";
target.FileName = logfile;
Using degloff idea as a starting point.
I wanted to create two log files; one detailed and one only showing the critical things. But the user has the right to change the directory to where they want the logs to be stored. Thus, I created this:
foreach(FileTarget target in LogManager.Configuration.AllTargets.Where(t => t is FileTarget).Cast())
var filename = Path.GetFileName(target.FileName.ToString().Trim('\''));
target.FileName = Path.Combine(logDir, filename);
Hope this helps.