aspnetcore: When I set builder.Logging.ClearProviders();, dotnet run stuck in building
I create an Asp.Net Core Web Api 7.0 project and use Serilog. After I setting builder.Logging.ClearProviders(); in Program.cs, I can run my project with Visual Studio, but when I use CLI: dotnet run or dotnet watch run, my project stuck in Building. When I remove it, I can use dotnet run normally.
Below is my Program.cs:
var logger = new LoggerConfiguration().ReadFrom
.Configuration(builder.Configuration)
.Enrich
.FromLogContext()
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);
My appsetting.json:
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-.log",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {Username} {Message:lj}{Exception}{NewLine}"
}
}
]
}
And Nuget Packages:
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
When I run dotnet run:
Has anyone encountered this kind of problem and can explain it?
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 25 (10 by maintainers)
I don’t believe there’s a hang, it just that nothing is logged.
This is the output with logging on:
This is what happens when you clear the loggers:
There’s no “Build succeeded” log in either case, the application just runs. You removed the console logger so nothing gets logged to the console from the application.