开发者

Storing Exceptions in flat file

In any ap开发者_StackOverflow社区plication, 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜