错误记录类中最好的异常处理策略是什么? [英] What is the best exception handling strategy within error logging classes?
问题描述
通常我输出到stderr在这种情况下,尽可能多的信息通常记录代码中的错误/异常以及原始日志/错误/异常。这样就有可能复制问题或理解它。
如果写入stderr失败,那么现在放弃 - 要么忽略它,要完全终止应用程序。
I am writing an error logging set of classes which will log to file, event log etc. What exception handling should be performed within these classes? For instance, say I have a LogError method, which is called from exception handlers, and writes to file. What is considered the best thing to do, should an error occur? Obviously, I should make these methods as fail safe as possible, but problems can always occur.
Generally I output to stderr as much information as possible in that case, often both the error/exception in the logging code, and the original log/error/exception. That way there's a chance of reproducing the problem or understanding it.
If writing to stderr fails then it's time to give up - either ignore it, to terminate the application entirely.
这篇关于错误记录类中最好的异常处理策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!