Use ThreadPool for logging the application?

advertisements

As a followup on this question discussing the use of the ThreadPool vs a dedicated thread:

When would you use a dedicated thread (with lowered priority) for applicationwide logging and when would you use the ThreadPool?


What I would do is completely dependent on the requirements of my app and its logging component.

If logging is mission-critical (maybe you need the ability to replay recent traffic based on the log, for example) then a dedicated thread is more likely the right approach.

If logging is 'best effort', then ThreadPool would be fine subject to other constraints on your app's required performance and latency. Async I/O for the logger would be fine here. Since you suggest lower priority for your putative logger thread, this may match your app's profile.

If more critical work is happening on the ThreadPool then I would not overload it to do logging, esp. if logging itself is important - you could well be doing synchronous, flushed I/O to write out the logs and that's a possible bottleneck depending on the volume of stuff that you wish to log.