【发布时间】:2021-12-23 09:52:03
【问题描述】:
我有以下 nlog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true"
internalLogFile="../app/internal.log"
internalLogToConsole="true"
internalLogLevel="Trace" >
<time type='AccurateUTC' />
<variable name="filePath" value="../app/logs/${shortdate}.log" />
<targets async="true">
<target xsi:type="Console" name="logconsole"
layout="${level}|${message}|${all-event-properties} ${exception:format=tostring}" />
<target xsi:type="File" name="logfile" fileName="${filePath}"
layout="${longdate}|${level}|${callsite}|${message}|${all-event-properties} ${exception:format=tostring}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile, logconsole" />
</rules>
</nlog>
此日志在 Windows 上运行没有问题,但在容器上运行它没有任何作用。
也没有internal.log,所以不知道在哪里看。
我将 Nlog 记录器附加到应用程序,如下所示:
private static void ConfigureLogging(HostBuilderContext host, ILoggingBuilder loggingBuilder)
{
loggingBuilder.ClearProviders();
loggingBuilder.AddConsole();
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
loggingBuilder.AddNLog(host.Configuration);
}
我尝试了多种方法,但到目前为止都没有运气。
任何帮助将不胜感激
谢谢
【问题讨论】:
-
您是否在
docker-compose.yml中配置了卷映射?您是否尝试过使用绝对路径而不是相对路径。前任。/app/logs/nlog_internal.log? -
是的!我也试过了:(