ASP0011: Suggest using builder.Logging over Host.ConfigureLogging or WebHost.ConfigureLogging
Value | |
---|---|
Rule ID | ASP0011 |
Category | Usage |
Fix is breaking or non-breaking | Non-breaking |
Cause
ConfigureLogging
isn't the recommended strategy for configuring logging in a minimal API application.
Rule description
ConfigureLogging
isn't the recommended strategy for configuring logging in a minimal API application.
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureLogging(logging =>
{
logging.AddJsonConsole();
})
var app = builder.Build();
app.Run();
How to fix violations
To fix a violation of this rule, use the Logging
property on the WebApplicationBuilder
to modify the logging configuration directly without the need for an additional ConfigureLogging
call.
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddJsonConsole();
var app = builder.Build();
app.Run();
When to suppress warnings
Do not suppress a warning from this rule.
Makipagtulungan sa amin sa GitHub
Ang pinagmulan para sa content na ito ay mahahanap sa GitHub, kung saan maaari ka ring lumikha at sumuri ng mga isyu at mga pull request. Para sa higit pang impormasyon, tingnan ang aming gabay sa contributor.