我在centos上运行一个aspnet core consol程序。我已经设置nlog.config来生成日志文件。在Windows开发环境中一切都很好,但是当我在Centos上运行它时,无法使用设置获取日志文件。 我的设置:
<target xsi:type="File" name="target1" fileName="${currentdir}\logs\${shortdate}-nlog.log" ... />
In centos:(click to show img) 它将在父目录中创建一个文件名“ demoBS \ logs \ 2019-06-26-nlog.log”。
谢谢,期待您的帮助!
Ps:Nlog.config
<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogFile="${currentdir}\logs\${shortdate}-internal.log"
internalLogLevel="Info" >
<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="target1" fileName="${currentdir}\logs\${shortdate}-nlog.log"
layout="${date}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}" />
<target xsi:type="Console" name="target2"
layout="${date}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<logger name="*" minlevel="Trace" writeTo="target2,target1" />
</rules>
</nlog>
答案 0 :(得分:0)
确保使用Unix路径而不是Windows路径。例如:
${currentdir}/logs/${shortdate}-nlog.log
反斜杠