I am having a strange issue with .NET Core 3.0 while using loggers.
The app works ok on Windows, but when I start it on Linux (Debian 10) as a daemon, it just keeps taking more and more memory.
The issue was first manifested when I was using NLog, then I switched to Serilog, but the issue is still here. The problem is not there when I remove NLog/Serilog.
Using memory snapshots and Jetbrains dotMemory all I get is a bunch of sbyte arrays that are created (probably) by NLog/Serilog.
When I disable logging to a file and leave just console logging – the problem disappears!
I tried adding manual calls to Garbage collector but that didn’t help.
We managed to create a workaround by adding MemoryMax parameter in ther .service file. It seems that garbage collector starts cleaning up when it is near the Max limit. (ie the limit is 150 MB and now the app is holding at 145 MB).
Does anyone have any idea what might be wrong? Or should I just address this issue with NLog and Serilog developers.
2
Answers
I have also noticed high memory consumption. There have been a few different things to try including:
To be certain about where the memory leak is happening though you will need to analyse the memory heap to look at what objects are using up the memory.
SeriLog Memory Leak using EF
NLog opens/closes the file for each file-write operation by default. This ensures the highest level of compatibility but it has a cost.
Try configuring NLog like this:
Do not use
<targets async="true">
if memory allocation is an issue.NLog ver. 4.7 fixes a performance issue when using
concurrentWrites="true"
together with NLog archiving-options on non-Windows-platforms. Until NLog ver. 4.7 is released then one should consider configuringconcurrentWrites="false"
if possible.See also: https://github.com/NLog/NLog/wiki/performance