${currentdir} 目标不再生成文件
${currentdir} target is not generating file anymore
我最近将我的 asp.net 核心项目升级到 .net core 2.2,同时更新了 NLog.Web.AspNetCore。
在我这样做之后(也许是巧合?)我注意到没有生成日志文件。
在我的配置中,这是我的目标:
<target xsi:type="File" name="allfile" fileName="${currentdir}/Logs/nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
经过一些调试我意识到如果我明确指定路径然后它会生成日志文件:
<target xsi:type="File" name="allfile" fileName="E:\Project\Logs\nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
我在配置中设置了throwExceptions="true"
,但是当没有生成文件时不会抛出异常,它只是默默地不创建文件。
为了进一步调试,我创建了一个控制台项目并添加了 nuget NLog.Web.AspNetCore 并复制了我的配置。现在在控制台项目中它工作正常并且正在调试输出目录中创建日志文件。
有什么方法可以调试为什么在我的主项目中没有用这个目标生成日志文件?
而不是使用 ${currentdir}
,然后考虑使用 ${aspnet-appbasepath}
(如果不是进程内托管,则为 ${basedir}
)
NLog InternalLogger 通常会在某些事情没有按预期工作时给出很好的提示。
请避免使用 throwExceptions="true"
,因为它用于单元测试,不适用于生产环境。
我最近将我的 asp.net 核心项目升级到 .net core 2.2,同时更新了 NLog.Web.AspNetCore。
在我这样做之后(也许是巧合?)我注意到没有生成日志文件。
在我的配置中,这是我的目标:
<target xsi:type="File" name="allfile" fileName="${currentdir}/Logs/nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
经过一些调试我意识到如果我明确指定路径然后它会生成日志文件:
<target xsi:type="File" name="allfile" fileName="E:\Project\Logs\nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
我在配置中设置了throwExceptions="true"
,但是当没有生成文件时不会抛出异常,它只是默默地不创建文件。
为了进一步调试,我创建了一个控制台项目并添加了 nuget NLog.Web.AspNetCore 并复制了我的配置。现在在控制台项目中它工作正常并且正在调试输出目录中创建日志文件。
有什么方法可以调试为什么在我的主项目中没有用这个目标生成日志文件?
而不是使用 ${currentdir}
,然后考虑使用 ${aspnet-appbasepath}
(如果不是进程内托管,则为 ${basedir}
)
NLog InternalLogger 通常会在某些事情没有按预期工作时给出很好的提示。
请避免使用 throwExceptions="true"
,因为它用于单元测试,不适用于生产环境。