Aspnet Core 5 single file deploy with Serilog - no log output
See original GitHub issueThe Serilog maintainers want you to have a great experience using Serilog, and will happily track down and resolve bugs. We all have limited time, though, so please think through all of the factors that might be involved and include as much useful information as possible 😊.
ℹ If the problem is caused by a sink or other related package, please try to track down the correct repository for that package and create the report there: this tracker is for the Serilog.AspNetCore package only.
Description There is no log output to console or log file
Reproduction program.cs
public static void Main(string[] args)
{
//var _config = new ConfigurationBuilder().AddJsonFile("appsettings.json");
//Log.Logger = new LoggerConfiguration()
//.MinimumLevel.Information()
//.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
//.Enrich.FromLogContext()
//.WriteTo.Console()
//.ReadFrom.Configuration(_config.Build())
//.CreateLogger();
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Application} {Level:u3}][{RequestId}] {SourceContext}: {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Application} {Level:u3}][{RequestId}] {SourceContext}: {Message:lj}{NewLine}{Exception}",
"path": "/var/log/aspnetcore5/applog.log",
"fileSizeLimitBytes": 100485760,
"rollOnFileSizeLimit": true,
"rollingInterval": "Day",
"retainedFileCountLimit": 3
}
}
]
}
}
Expected behavior logs to console and file. The same app works in dotnet core 3.1
Relevant package, tooling and runtime versions What Serilog version are you using, on what platform? Serilog.AspNetCore 3.4.0 Docker image Alpine 3.12 x64 from Microsoft https://github.com/dotnet/dotnet-docker/tree/master/src/aspnet/5.0/alpine3.12/amd64
Additional context The same app works when it is not bundled/compiled into a single file or standalone deployment.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Hi, @alberk8, @pedroansilva See issues: #245, #239. I’ve updated the documentation here:
I had a similar problem when switching the project to .NET 5. What solved it is moving the configuration from
appsettings.json
to code - and not reading the JSON file.