12

我正在测试 ELMAH,并特意在我的应用程序中关闭了 ELMAH 日志的数据库连接,以查看如果数据库不可用,生产中会发生什么。

似乎 ELMAH 无法捕获自己的错误——当 SQL 数据库日志失败时,AXD 文件不可用。

如果数据库不可用,ELMAH 的预期行为是什么?

如果发生这种情况,我该如何诊断我的错误?

4

4 回答 4

12

似乎ELMAH无法捕获自己的错误

ELMAH 确实在某种程度上捕获了自己的错误。如果ErrorLogModule在尝试记录错误时遇到异常,则将记录产生的异常发送到标准 .NET Framework 跟踪工具。请参阅1.0 来源的第 123 行。另请参阅 ASP.NET 文档中的以下演练,以获取使用 ASP.NET 跟踪的标准 .NET Framework 跟踪:

演练:将 ASP.NET 跟踪与 System.Diagnostics 跟踪集成

SQL 数据库日志失败时,AXD 文件不可用。

那是对的。SQL Server 数据库连接必须能够在使用时查看存储在 SQL Server 数据库中的错误SqlErrorLog

如果数据库不可用,ELMAH 的预期行为是什么?

例如,如果 SQL Server 数据库已关闭,SqlException则在记录期间会发生 a。然后,ELMAH 会将SqlException对象内容发送到标准的 .NET Framework 跟踪工具。

如果发生这种情况,我该如何诊断我的错误?

这里最好的选择是启用错误记录电子邮件发送。如果数据库已关闭,则邮件网关很可能已启动,您仍会收到错误通知。实际上,错误将记录在某些邮箱中。这还有一个额外的好处,如果邮件网关曾经关闭,那么数据库很可能会启动并且错误会在那里记录。但是,如果两者都出现故障,那么您将需要认真检查您的生产基础架构,并可能采取措施通过其他措施监控系统的健康状况。

于 2009-06-16T22:45:54.457 回答
0

您始终可以使用 xml 文件选项来记录错误。

于 2009-04-16T21:18:01.987 回答
0

Not really sure about ELMAH but expected behaviour of such logging frameworks is not to throw any exceptions if something goes wrong with them. I.e. if ELMAH's database is down I'd assume it will just not log the errors to database.

As suggested above you can/should use alternative sinks - email or flat file.

于 2009-04-16T21:29:42.693 回答
0

I think you're mixing up contexts a bit.

ELMAH's behavior if the database isn't available is to not log errors to the database. If an exception is thrown on the server or if you raise an exception via an ErrorSignal, ELMAH is going to let that exception pass through to either a yellow screen or a custom errors page (your setting.)

Since Errors.axd page is only accessible to those that should be seeing it (ideally,) it is okay to present that error to the user.

The bottom line is that if the errors database is down you can't diagnose errors. For us, if that were the case, we'd have bigger problems since the error database sits with the production database.


I would also advocate against using XML logging for your primary logging source. SQL server is going to give you the best performance without having to manage the files. With XML logging that is not the case.

于 2009-04-16T21:39:46.787 回答