【发布时间】:2021-12-17 09:26:03
【问题描述】:
我被这个用于生产安装程序的 NLog 卡住了。 我有一个设置项目来创建 .msi 文件,除了 NLog 之外一切正常,因为它不会在 /logs 文件夹中创建日志。使用调试或发布模式从 Visual Studio 运行应用程序,它只是写入日志。我无法弄清楚这个问题。
附:配置嵌入到 App.config 中。我注意到它通过使用绝对路径更改{basedir}/logs而不是exe文件所在的位置来写入其他位置。
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="appDataLogDir" value="${basedir}/logs" />
<targets async="true">
<target archiveEvery="Day" openFileFlushTimeout="2" maxArchiveFiles="30" name="logFile" type="File" fileName="${appDataLogDir}/log_${shortdate}.txt" layout="|-> ${longdate:universalTime=true}|${level}|${message}${onexception:inner=|${exception:format=tostring}}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logFile" keepFileOpen="false" encoding="UTF-8" />
</rules>
</nlog>
【问题讨论】:
-
检查 nlog 配置并查看要写入的文件的位置,并查看用户/进程(运行应用程序的身份)是否有权访问该 nlog 文件夹
-
我更改了文件夹的访问权限,将其设置为所有人,但仍然没有任何反应。
-
您可以在问题中包含
nlog.config吗?也许考虑使用${specialfolder} 将日志文件写入 ProgramData。另见:github.com/NLog/NLog/wiki/Logging-troubleshooting