如何在appsettings.json中为NLog日志规则指定多个过滤器

6
我是一位有用的助手,可以为您翻译文本。
我已经看到了使用XML的多个when过滤器的示例,但我正在使用appsettings.json进行所有配置。我已经能够实现单个when过滤器,但是当我尝试添加另一个过滤器时,会出现重复键错误。 有什么想法吗?
这个可以工作 -
"rules": [
  {
    "logger": "*",
    "minLevel": "Debug",
    "writeTo": "db",
    "filters": {
      "when": { 
        "condition": "equals('${event-properties:sublevel}','diagnostic')",
        "action": "Ignore"
      }
    }
  }
]

参见:https://github.com/NLog/NLog.Extensions.Logging/issues/491 - Rolf Kristensen
如果您升级到NLog 4.7.9并使用答案中显示的配置,则它将与NLog.Extensions.Logging 1.7.1一起正常工作。 - Rolf Kristensen
1个回答

6
这个限制已经在NLog.Extensions.Logging 1.7.2中得到解决,现在支持以下工作示例:
"rules": [
    {
        "logger": "*",
        "minLevel": "Trace",
        "writeTo": "Console",
        "filterDefaultAction": "Log",
        "filters": [
            {
                "type": "when",
                "condition": "equals('${event-properties:sublevel}','diagnostic')",
                "action": "Ignore"
            },
            {
                "type": "when",
                "condition": "contains('${message}','HeartbeatResponse')",
                "action": "Ignore"
            }
        ]
    }
]  

1
看起来是在你的评论发布两天后发布的 :) https://www.nuget.org/packages/NLog.Extensions.Logging/ - Doctor Coder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接