Search code examples
exceptionfileflat

Storing Exceptions in flat file


In any application, we can do error logging using flat file system.

How do we handle a scenario when there are multiple users having exceptions which are logged in the same flat file?

Many Thanks.


Solution

  • You could create one thread for writing exceptions, reading from a queue. The actual exception handling code would write the exception to the queue. Since there's only one thread writing the file, everything is serialized. Of course, you need a thread-safe queue implementation, but your language or framework probably provides one.