1
votes

I'm using Serilog with ASP.NET Core 2.1. I want all log entries with a level of Information or higher to go to SQL Server and the console. I want only exceptions and higher to go to Email.

The Email sink is not being filtered and is also getting the same log entries as MSSQLServer and Console. It seems to be ignoring restrictedToMinimumlevel.

From my appsettings.json.

"Serilog": {
  "MinimumLevel": "Information",
  "WriteTo": [
    {
      "Name": "MSSqlServer",
      "Args": {
        "connectionString": "<removed>",
        "tableName": "Logs"
      }
    },
    {
      "Name": "Console"
    },
    {
      "Name": "Email",
      "Args": {
        "fromEmail": "<removed>",
        "toEmail": "<removed>",
        "mailServer": "<removed>",
        "mailSubject": "Test",
        "restrictedToMinimumlevel": "Error"
      }
    }
  ]
}

What am I doing wrong?

1
I expect it’s because you have a lowercase l at the start of what should be Level. - serpent5
@KirkLarkin, Thanks, that was it! - Alan T

1 Answers

1
votes

Serilog's setting of the configuration settings values is case-sensitive and as such it's not able to find the restrictedToMinimumlevel argument because of that.

It should be restrictedToMinimumLevel with an uppercase L on Level.