This is the code I am using to pass the file path and giving the file path in NLOG.config file in DLL (class library) from other web application to generate the logs file . But I am unable to do this.
string filePath = path;
var target = (FileTarget)LogManager.Configuration.FindTargetByName("logFile");
target.FileName = "" + filePath + "/current.log";
LogManager.ReconfigExistingLoggers();
Normally there is only one global NLog.config for the entire application.
Instead of modifying the individual targets in the active NLog-config, then I think it is easier to modify the NLog global variables.
https://github.com/NLog/NLog/wiki/Gdc-layout-renderer
https://github.com/NLog/NLog/wiki/Var-Layout-Renderer
You could do it like this:
<target type="file" filename="${gdc:item=MyAppPath}current.log" />
And then at startup execute this command to modify the GDC:
NLog.GlobalDiagnosticsContext.Set("MyAppPath", filePath + "/");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.