【发布时间】:2019-01-21 14:58:50
【问题描述】:
我的项目中有最新版本的Common.Logging (3.4.1) 和NLog (4.5.11)。按照说明在 app.config 中将 Common.Logging 与 NLog 绑定在一起,现在可以进行日志记录了。
现在我想要结构化日志记录:
private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
var message = new IDontKnowWhat("A structured message for ClientId {ClientId}", ClientId.ToString());
_logger.Info(message);
以上是伪代码,不知道如何构造消息对象。 而且,_logger.InfoFormat 似乎适用于 String.Format,而不是结构化日志记录。
除了使用ThreadVariablesContext/GlobalVariablesContext/NestedThreadVariablesContext之外,Common.Logging 是否提供结构化日志记录?
【问题讨论】:
-
认为您正在等待这个问题:github.com/net-commons/common-logging/issues/159(遗憾的是,修复这将是一个“破坏性”更改,因为 Common-Logging 出于某种原因尝试执行解析和格式化,而不是让日志框架完成这项工作)。 SerilogLogger 执行 hack 以解决 Common-Logging-Framework 的限制,因此可以使用结构化日志记录。
-
看起来确实如此.. 我现在正在尝试使用 LibLog。我已经使用 LibLog/NLog 组合进行结构化日志记录,只是在显示通过 OpenMappedContext 传入的信息时出现问题。
标签: c# nlog common.logging structured-logging