Closed hampusborgos closed 7 years ago
Hi @hjnilsson,
Thanks for dropping by. Just wondering how you are instantiating Serilog and the Seq Sink?
@hjnilsson as @merbla is suggesting, it looks like you're creating multiple instances of the Seq sink. Just like HttpClient
, only a single Seq sink instance (per server, at least) should be created within an app. Check out:
https://github.com/serilog/serilog/wiki/Lifecycle-of-Loggers
for some info on how Serilog expects loggers to be created and reused.
Closing as this thread has gone quiet, but please get back in touch if you need more information or still think there's a problem here. Thanks!
SeqSink leaks memory through creating new instances of
HttpClient
.HttpClient
is intended to be instantiated once, and then reused for all future requests. Creating newHttpClient
s will leak memory and network connections over time.You can read more details on this subject in this article: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
You can also find more details in the Windows azure performance manual here: https://docs.microsoft.com/en-gb/azure/architecture/antipatterns/improper-instantiation/
The fix is updating the variable here: https://github.com/serilog/serilog-sinks-seq/blob/dev/src/Serilog.Sinks.Seq/Sinks/Seq/SeqSink.cs#L65
to be
static
scope, and making the necessary changes to the use of the object so that it works through reuse (ie. setBaseAddress
on the request, and not on theHttpClient
). There is also no need to callDispose
on the object in the destructor as it has no effect (HttpClient
cannot be disposed).See this image for example of how hundreds of
HttpClient
objects are created (and leaked) after logging through Seq: