Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High Performance Logging in .NET

What is the best direction to go if we are logging every user action in a web application that could potentially have 20K users on at the same time? Should we build a list cache of the log data, and persist it to the database after a certain amount of time or threshold? Are there any good libraries or techniques that can do this?

like image 853
Mike Flynn Avatar asked Mar 17 '26 19:03

Mike Flynn


1 Answers

Should we build a list cache of the log data, and persist it to the database after a certain amount of time or threshold

If you cache and you crash, goodbye logs.

Are there any good libraries or techniques that can do this?

It is best to use a flexible logging mechanism that you can turn on and filter at will, that has ultra high performance when disabled.

I recommend using an existing library. You don't want bugs in your logging to mask bugs in production.

NLog (and other such logging libraries) can be used to do this fairly easily. It is designed to suit the needs of a large range of projects, and has techniques that allow you to have a very low performance impact when you have disabled it. It also has built-in multi-threaded/asynchronous logging support.

That being said, there are a lot of reasonable quality .Net logging libraries out there. Check out this question for some quality comparison opinions (more libraries are represented than the title suggests): log4net vs. Nlog

like image 186
Merlyn Morgan-Graham Avatar answered Mar 19 '26 10:03

Merlyn Morgan-Graham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!