nlog - NLog 致命消息从未记录?
问题描述
我在 C# 控制台应用程序中使用 NLog 4.7.10。我的信息、错误和警告消息按预期出现在我的日志文件中,但致命消息永远不会出现。我的代码如下所示:
NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
logger.Fatal("This never appears in the log file!");
logger.Info("This info message is logged in the log file.");
logger.Error("This error message is logged in the log file.");
logger.Warn("This warning message is logged in the log file.");
我认为我的 nlog.config 中没有任何内容会导致问题:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="d:\tmp\log.txt">
<variable name="defaultLayout" value="${date:format=dd MMM yyyy HH\:mm\:ss} [${level}]: ${message:withException=true}" />
<targets>
<target name="logfile" xsi:type="File"
fileName="${basedir}/logs/foo.log"
archiveOldFileOnStartup="true"
layout="${defaultLayout}"
archiveFileName = "${basedir}/logs/archives/foo ${date:format=yyyy-MM-dd HHmmss}.log"
archiveNumbering = "Rolling" />
<target name="console" xsi:type="ColoredConsole" layout="${defaultLayout}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>
什么可以过滤掉致命消息?
解决方案
我发现了这个问题。我们的一个函数,其目的是设置日志文件路径(给定一个数据库值)有一个副作用。它还设置了最大日志级别。在这种情况下,它将最大日志级别设置为错误。
抱歉打扰。
推荐阅读
- php - 致命错误:在 /var/www/vendor/laminas/laminas-db/src/Adapter/Adapter.php 中找不到特征“Laminas\Db\Adapter\Laminas\Db\Adapter\AdapterInterface”
- laravel - 在编辑页面上选中 Laravel Livewire 复选框
- azure-data-explorer - Kusto - 值的范围颜色
- linux - 移动,复制文件而不使用太多内存
- django - 如何将类添加到自定义小部件?
- database-partitioning - 为什么局部变量在选择时会包含其他分区?
- java - 与控制台相比,导航中显示的输出和实际 url 不同
- java - 我在我的 android studio 上运行我的第一个 java 程序时遇到问题
- powershell - 将多个 CSV 文件合并为一个具有不同列的文件
- javascript - AmCharts 4 如何在 LineSeries 末尾显示最后一个值