Description
Description
UseSerilog(writeToProviders: true)
is causing Microsoft.Extensions.Logging.EventSource.EventSourceLogger
instances to leak in memory. Honestly I'm not sure if this is something that could be prevented on serilog's side or should be addressed on dotnet core runtime or, maybe, just better documented on serilog's aspnetcore. As of now, our workaround has been removing EventSourceLoggerProvider
from service collection as we don't need to write into it.
Reproduction
A reproduciple sample can be found here: https://github.com/spolaore/serilog-leak
Steps to reproduce:
dotnet new webapi
(with dotnet core 3.1 or net 5)- Wire up serilog with write to providers feature enabled:
Host.CreateDefaultBuilder(args)
.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext(), writeToProviders: true)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
- Run it inside a linux container
- Run load test with bombardier:
bombardier --http1 -k -c 1 -d 100s https://localhost:443/weatherForecast
Expected behavior
Expected not to observe EventSourceLogger
objects leaking in heap
Relevant package, tooling and runtime versions
Serilog 4.1.0
net5.0 framework
mcr.microsoft.com/dotnet/sdk:5.0
Additional context
heapdumps-writeToProviders-enabled.zip
heapdump-writeToProviders-disabled.zip
After load testing the reproduciple sample, this is the heap dump generated with dotnet-gcdump
tool: