Search code examples
c#.netlogging.net-coreserilog

Formatting Serilog logs


How do I remove unnecessary information in Serilog logs? The docs seem to have nothing about this.

I want to remove the red part

I want to remove the red part in the image above

This is my config in appsettings.json

  "Serilog": {
"Using": [ "Serilog.Settings.Configuration" ],
"Filter": [
  {
    "Name": "ByIncludingOnly",
    "Args": {
      "expression": "@Level in ['Debug']"
    }
  }
],
"MinimumLevel": {
  "Default": "Debug",
  "Override": {
    "System": "Debug",
    "Microsoft": "Debug"
  }
},
"WriteTo": [
  {
    "Name": "Seq",
    "Args": {
      "serverUrl": "http://localhost:5341/",
      "compact": true
    }
  },
  {
    "Name": "Console"
  },
  {
    "Name": "File",
    "Args": {
      "path": "D:\\dev.SmartCity.Peafowls.Logs\\PeafowlsLog_.txt",
      "rollingInterval": "Day",
      "rollOnFileSizeLimit": true,
      "fileSizeLimitBytes": 4194304
    }
  }
] }

Solution

  • Its not completly clear what you want. I can only assume, that you want to display only the Log-Message to the console.

    To achieve that, you can add the following outputTemplate to your block:

    {
        "Name": "Console",
        "Args": {
          "outputTemplate":  "{Message}{NewLine}"
        }
    }