7

I have recently set up Serilog to handle my logging activities to the database. However, when I started it up, I noticed plenty of System and Microsoft activities filling up the rows. I have tried to add several overrides in my Serilog filters but some like Executed action method and Db Command remains. What do I need to override to remove them from my logs?

My appsettings.json

"Serilog": {
    "MinimumLevel": "Information",
    "Override": {
      "Microsoft": "Error",
      "Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory": "Error",
      "Microsoft.EntityFrameworkCore.Database.Command": "Error",
      "Microsoft.AspNetCore.Hosting.Internal.WebHost": "Error",
      "ToDoApi": "Error",
      "Engine": "Error",
      "System": "Error"
    },

2 Answers 2

4

I found out a much better way. In my Program where I configure the logger:

Log.Logger = new LoggerConfiguration()
               .ReadFrom.Configuration(Configuration)
               .Filter.ByExcluding(Matching.FromSource("Microsoft"))
               .Filter.ByExcluding(Matching.FromSource("System"))
               .Enrich.FromLogContext()
               .CreateLogger();

This way I can control what gets logged.

Sign up to request clarification or add additional context in comments.

Comments

2

Your MinimumLevel configuration section isn't quite right: Override should be under it. You need:

  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Error",
        "ToDoApi": "Error",
        "Engine": "Error",
        "System": "Error"
      }
    }
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.