[英]Set ApplicationData folder on app.config and get it on Nlog.config
I'd like to set the path of NLog log file on app.config. 我想在app.config上设置NLog日志文件的路径。
I know how to set the applicationData folder on NLog.config. 我知道如何在NLog.config上设置applicationData文件夹。 It's like that:
就像那样:
<target xsi:type="File"
name="logFileCsv"
fileName="${specialfolder:folder=ApplicationData}/something/something.log">
And if I use the NLog.Extended I know how to get key values from app.config and use them on NLog.config, like that: 如果我使用NLog.Extended,我知道如何从app.config获取键值,并在NLog.config上使用它们,如下所示:
<target xsi:type="File" name="logFileCsv" fileName="${appsetting:name=LogPath">
And on app.config should be like this 而在app.config上应该是这样
<add key="LogPath" value="${APPDATA}/something/something.log" />
But it's not working the way I want. 但这不是我想要的方式。 NLog is creating the log file on
c:\\..\\${APPDATA}/something/something.log"
NLog正在
c:\\..\\${APPDATA}/something/something.log"
上创建日志文件c:\\..\\${APPDATA}/something/something.log"
So, I'd like to know how to set the ApplicationData folder on app.config to be understandable by NLog? 因此,我想知道如何将app.config上的ApplicationData文件夹设置为NLog可以理解的?
Unfortunately the ${appsetting}
won't evaluate the value. 不幸的是
${appsetting}
不会评估值。
As work around you can do: 解决此问题时,您可以:
<target fileName="${APPDATA}/${appsetting:name=LogPath}" />
note: wrapping in a ${replace} also won't work 注意:使用$ {replace}换行也将不起作用
I tried the answer of Julian , but it wasn't utterly successful: 我尝试了朱利安(Julian)的答案 ,但没有完全成功:
Error FileTarget(Name=logFileCsv): Failed write to file '\\\\something\\something.log
However, with that help and workaround, I figure out how to do it: So in App.config just add the final path: 但是,有了该帮助和解决方法,我就知道了如何做到这一点:因此,在App.config中,只需添加最终路径即可:
<add key="LogPath" value="\something\something.log"/>
and in NLog.Config I did this: 在NLog.Config中,我这样做:
<target xsi:type="File" name="logFileCsv" fileName="${specialfolder:folder=ApplicationData}/${appsetting:name=LogPath}">
And now the log is written on the right path: C:\\Users\\user\\AppData\\Roaming\\something\\something.log 现在将日志写在正确的路径上:C:\\ Users \\ user \\ AppData \\ Roaming \\ something \\ something.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.