繁体   English   中英

想要将动态文件路径从主Web应用程序传递到单独的DLL。 该DLL是使用NLog单独完成的

[英]Want to pass dynamic File path from main web application to a separate DLL. That DLL is separately done using NLog

这是我用来传递文件路径并从其他Web应用程序提供DLL(类库)中NLOG.config文件中文件路径的代码,以生成日志文件。 但是我做不到。

string filePath = path;
var target = (FileTarget)LogManager.Configuration.FindTargetByName("logFile");
target.FileName = "" + filePath + "/current.log";
    LogManager.ReconfigExistingLoggers();

通常,整个应用程序只有一个全局NLog.config。

我认为与其修改活动NLog-config中的单个目标,不如修改NLog全局变量更容易。

https://github.com/NLog/NLog/wiki/Gdc-layout-renderer

https://github.com/NLog/NLog/wiki/Var-Layout-Renderer

您可以这样做:

<target type="file" filename="${gdc:item=MyAppPath}current.log" />

然后在启动时执行以下命令来修改GDC:

NLog.GlobalDiagnosticsContext.Set("MyAppPath", filePath + "/");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM