最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Serilog logging too much information - Stack Overflow

programmeradmin1浏览0评论

I have a Blazor Server app being hosted in a Azure App Service and want to customize the logging. I’m trying Serilog for the first time and after watching a couple videos I as able to get it to at least write out the console fairly easy. However, I get a whole bunch of extra .Net chatter that I would like to exclude. I’m assuming once I push the code out to Azure it would also log stuff going on with Azure itself.

Is it possible to exclude all of the extra logging? I found an article that talks about setting the Database.Command:None and Infrastructure:None. That seemed like it worked when I was using just the built in ILogger but doesn’t seem to effect Serilog.

Are there settings in Serilog with I can have it just log what I put in my apps call to _log.LogInformation or _log.LogError?

Nuget Package

Serilog.AspNetCore

Program.cs

builder.Logging.ClearProviders();
builder.Host.UseSerilog((context, config) => config.ReadFrom.Configuration(context.Configuration));

Appsettings

"Serilog": {
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft.AspNetCore": "Information"
    }
  },
  "WriteTo": [
    {
      "Name": "Console",
      "Args": {
        "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u4}: {Message:lj}{NewLine}{Exception}]"
      }
    }
  ],
  "Microsoft.EntityFrameworkCore.Database.Command": "None",
  "Microsoft.EntityFrameworkCore.Infrastructure": "None"
},

Currently what I see in the console.

I have a Blazor Server app being hosted in a Azure App Service and want to customize the logging. I’m trying Serilog for the first time and after watching a couple videos I as able to get it to at least write out the console fairly easy. However, I get a whole bunch of extra .Net chatter that I would like to exclude. I’m assuming once I push the code out to Azure it would also log stuff going on with Azure itself.

Is it possible to exclude all of the extra logging? I found an article that talks about setting the Database.Command:None and Infrastructure:None. That seemed like it worked when I was using just the built in ILogger but doesn’t seem to effect Serilog.

Are there settings in Serilog with I can have it just log what I put in my apps call to _log.LogInformation or _log.LogError?

Nuget Package

Serilog.AspNetCore

Program.cs

builder.Logging.ClearProviders();
builder.Host.UseSerilog((context, config) => config.ReadFrom.Configuration(context.Configuration));

Appsettings

"Serilog": {
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft.AspNetCore": "Information"
    }
  },
  "WriteTo": [
    {
      "Name": "Console",
      "Args": {
        "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u4}: {Message:lj}{NewLine}{Exception}]"
      }
    }
  ],
  "Microsoft.EntityFrameworkCore.Database.Command": "None",
  "Microsoft.EntityFrameworkCore.Infrastructure": "None"
},

Currently what I see in the console.

Share Improve this question asked Mar 6 at 14:51 CavermanCaverman 3,77910 gold badges71 silver badges141 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You'll have to configure both the general and Serilog related levels.

To filter out the logging that does not originate from your own code, set it a to a high level like warning or error. You don't want to completely silence it, otherwise you'll miss any real errors.

Configure a lower level -- e.g. information -- as a Serilog override, matching the namespace (or a part of it) of your application.

As an example, in case your application would have namespaces Contoso.Application.Server and Contoso.Application.Client, then below Contoso registration would cover both and any informational and upwards log statements from code within that namespace would be included in the log output.

{
  "Logging": {
    "LogLevel": {
      "Default": "Error"
    }
  },
  "Serilog": {
    "MinimumLevel": {
      "Default": "Error",
      "Override": {
        "Contoso": "Information"        
      }
    }
  }
}
发布评论

评论列表(0)

  1. 暂无评论