【发布时间】:2020-07-21 02:55:51
【问题描述】:
我看过以下video 解释有关 Serilog 的内容。我也想在我的应用程序中使用结构化日志记录(至少是其中的一部分),但我更喜欢使用 NLog (1),因为它已经是我们堆栈的一部分,我们已经习惯了它并且更喜欢使用相同的记录器在我们的项目中,以及 (2) 我已经阅读了比较 here 并且似乎 NLog 的性能更高。
所以我也读到了 NLog support structured logging,并且我已经在测试应用程序中实现了它,没有问题。效果很好。
我在视频中看到并喜欢 Serilog 的是,在写入控制台时,它会突出显示传递给日志记录函数的参数,如下所示:
我想在我目前正在构建的控制台应用程序上使用相同的功能。我已经尝试过Console 目标和ColoredConsole,但没有这种效果。在 NLog 中可以吗?
这是我的目标配置:
<target name="file"
xsi:type="File"
archiveEvery="Day"
archiveFileName="Logs\log.{#}.txt"
fileName="Logs\log.txt"
archiveNumbering="DateAndSequence"
archiveDateFormat="yyyy-MM-dd"
archiveAboveSize="104857600"
maxArchiveFiles="30"
layout="${longdate} | ${uppercase:${level}} | ${logger} | ${threadid} | ${message} ${exception}"
/>
<target xsi:type="ColoredConsole"
name="ColorConsole"
layout="${uppercase:${level}}: ${message} ${exception:innerFormat=Message,StackTrace}"
header="Memoriez API"
useDefaultRowHighlightingRules="false"
>
<highlight-word foregroundColor="Green" ignoreCase="true" text="info" wholeWords="true" />
<highlight-word foregroundColor="Red" ignoreCase="true" text="warn" wholeWords="true" />
<highlight-word backgroundColor="Red" foregroundColor="White" ignoreCase="true" text="error" wholeWords="true" />
<highlight-row backgroundColor="DarkRed" foregroundColor="Yellow" condition="level == LogLevel.Fatal" />
</target>
【问题讨论】: