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.
Samarbeid med oss på GitHub
Du finner kilden for dette innholdet på GitHub. Der du også kan opprette og se gjennom problemer og pull-forespørsler. Hvis du vil ha mer informasjon, kan du se vår bidragsyterveiledning.