- 如果您的错误日志记录代码失败,您会怎么做?
- 您如何确保其当前正常工作?
- 你怎么知道它是否不起作用?
- 你如何测试它在生产环境中的工作?
- 如果一切都失败了,我应该抛出异常吗?
下面的代码使用 Microsoft 的 Enterprise Library Logging Application Block。你如何让它“更好”?
using Microsoft.Practices.EnterpriseLibrary.Logging;
class Program
{
static void Main(string[] args)
{
try
{
// Trying to write some data to the DB
...
}
catch (Exception ex)
{
LogHelper.LogException(ex, "Trying to write to the DB");
}
}
}
public class LogHelper
{
public static void LogException(Exception ex, string exceptionType)
{
try
{
// Simplified version, only logging the message
Logger.Write(exceptionType);
}
catch
{
// What do you do here???
}
}
}