How to specify multiple filters for NLog logging rule in appsettings.json

Viewed 753

I've seen examples of multiple when filters using XML but I'm using appsettings.json for all configuration. I've been able to implement a single when filter but when I try to add an additional filter I get a duplicate key error. Any ideas?

This works -

"rules": [
  {
    "logger": "*",
    "minLevel": "Debug",
    "writeTo": "db",
    "filters": {
      "when": { 
        "condition": "equals('${event-properties:sublevel}','diagnostic')",
        "action": "Ignore"
      }
    }
  }
]
1 Answers

This limitation has been fixed with NLog.Extensions.Logging 1.7.2, that now supports this working example:

"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"
            }
        ]
    }
]  
Related