簡體   English   中英

使用 Common.Logging 和 NLog 進行結構化日志記錄

[英]Structured logging with Common.Logging and NLog

我的項目中有最新版本的Common.Logging (3.4.1) 和NLog (4.5.11)。 按照說明將 Common.Logging 與 app.config 中的 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一起工作,而不是結構化日志記錄。

確實Common.Logging提供結構化的記錄,除了使用ThreadVariablesContext / GlobalVariablesContext / NestedThreadVariablesContext?

對我來說幸運的是,Common.Logging 開發團隊目前正在解決這個問題: Common.Logging.NLog45 支持結構化日志 #176

結帳serilog以進行結構化日志記錄。 如果你的需求是使用 NLog,serilog 也有一個 Sink 到 NLog。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM