Traditionally, keepConnection was turned on because of the exact reason you were talking about, it would be awful to quickly open / close a large number of connections. If disabled, NLog will open the connection, write a single log statement, and close for each connection.
If you want connections to close, you can always use a wrapper to increase the efficiency of logging by writing logs in batches
Check the asynchronous buffer: https://github.com/nlog/nlog/wiki/AsyncWrapper-target
The default batch size is 100, which is probably right for you. In this case, it would be nice to disable keepConnection. In this case, NLog will queue 100 log messages, and then open the connection, record all of them, and then close the connection.
In addition, 5,000 per day is really small for logging, which goes up to 4 log / minute, of course, is not a big load. Something seems to be wrong.
First of all, it comes to your mind that you are using SQL Server, which usually requires transactions. By default, it is disabled in NLog, so be sure to explicitly include transactions in the log config.
useTransactions=true
https://github.com/nlog/nlog/wiki/Database-target
source share