Making logging async without self destruction

I was initially using the async delegate pattern to make logging asynchronous in the application. The problem is that whether you use this way or thread pool, ultimately, it uses thread pool threads and because everything is busy logging, your application will be slow.

Timers may fail to function, and generally, you have lost the advantages of making logging asynchronous.

So, I used a pattern I did a few years ago - with a small tweak. Always make error/fatal/warning logs synchronous, for the rest append to a string builder, then use a timer (a single timer) which runs every 1000 ms and which will clear the string builder "buffer" and do whatever you want to do within this.

This way, you use minimal thread pool threads, and your logging is still asynchronous enough...

Comments

Popular posts from this blog

Tutorial: Using Google Cloud Storage from C# and .NET

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?

The ridiculous interview experience