Posts

Showing posts from May, 2011

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...