[英]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.