Is the purpose of the Nlog database to use keepConnection or not?

I am using NLog in an asp.net 2.0 application; it receives a lot of traffic and records a lot of data (an average of about 5,000 journal entries per day), both for error reporting and for statistical purposes. It uses two different database targets, each of which calls a stored procedure, and both with the same connection string (SQL Server).

After copying the target definition from any documentation, both targets have a keepConnection set to true, which, by default, I know. My question is: is this desirable? I often see many open connections opened by NLog in the database (looking at open processes in the activity monitor), and sometimes I get connection failures in NLog; I am tempted to try to disable keepConnection, but I am also concerned about the large number of open and closed operations. I did not look at the source code, and I'm not sure that I can still answer my question, so I don’t know how the connection works regarding the pool in which its parent application is located.

Any thoughts, warnings or tips? I know that my question is a bit foggy - it's just a hat, I can find nothing more than documentation about this attribute with bare bones, and would like to get some feedback on the pros and cons - that is, why it was placed on NLog in first place? Thank you

+4
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/1402910/


All Articles