问题描述
我正在写一个错误日志记录集,它将记录到文件,事件日志等。在这些类中应该执行什么异常处理?例如,说我有一个LogError方法,它是从异常处理程序调用的,并写入文件。什么被认为是最好的事情,应该出现错误?显然,我应该使这些方法尽可能的失败,但是问题总会发生。通常我输出到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.
这篇关于错误记录类中最好的异常处理策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!