Hi,
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.
Hi,
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.
You'd acquire a write lock to the logfile before logging an exception. If someone else tries to log while you're in the middle of writing, their lock request will wait until you release it.
Alternatively, if such a thing is available, use an atomic file write operation to log the entire exception.
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.