Search code examples
c#asp.netexceptionelmah

Catch error within ELMAH SQL logging


How would I go about catching an error within ELMAH when it tries to log an error to a SQL database. Currently, the SQL logging is working as expected, but what if the database is down? How would I be able to log exceptions while the database is down?

ASP.Net 2.0 using C# //yes I am working on defects for a client with a legacy application


Solution

  • I have written an answer to this problem which boils down to this:

    • write a custom error log module in order to capture the fact that no message was logged
    • write a custom tracer to enable retrieval of the exception that was thrown when the logging failed

    However I would like to point out that this is not a recommended way of monitoring your sql server. You don't want to have to wait for an error before realizing that the error cannot be logged / traced. So I would recommend setting up an independent SQL Server monitor that will be your first line of defense against such a problem.