【问题标题】:How do I log a custom field in NLog to database using Microsoft.Extensions.Logging?如何使用 Microsoft.Extensions.Logging 将 NLog 中的自定义字段记录到数据库?
【发布时间】:2020-05-29 14:05:34
【问题描述】:

我将 Microsoft.Extensions.Logging 与 NLog 一起使用。我的应用是 .NET Core 3.1。

我想使用自定义字段扩展日志记录。

是否可以或者我需要直接使用 NLog?

  <parameter name="@custom_guid" layout="${custom_guid}"/>

         var config = new Dictionary<string, object>();
         config.Add("custom_guid", "test"); 
         _logger.LogInformation("Test message", config);

【问题讨论】:

标签: c# logging nlog asp.net-core-3.1 microsoft-extensions-logging


【解决方案1】:

你可以这样做:

var config = new Dictionary<string, object>();
config.Add("custom_guid", "test");

using (_logger.BeginScope(config))
{
   _logger.LogInformation("Test message");
}

并使用${mdlc:custom_guid}

【讨论】:

  • 我用过:${event-properties:custom_guid},这对我有用。谢谢
猜你喜欢
  • 2012-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多