views:

671

answers:

4

I'm testing ELMAH and have deliberately turned off the database connection for the ELMAH log in my application to see what will happen in production if the DB isn't available.

It seems that ELMAH can't trap its own errors- the AXD file isn't available when the SQL databse log fails.

What is the intended behavior of ELMAH if the database isn't available?

How can I diagnose my errors if this occurs?

A: 

You can always use the xml file option to log your errors.

A: 

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.

Rashack
A: 

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.

Gavin Miller
While debugging with ELmah.dll in the web\bin directory, the web app threw an error in one of the elmah source files (indicated by the information present from the elmah.pdb) when it couldn't get to the database. So - it will throw an unhandled exception. Will other ELMAH loggers work in that case?
Caveatrob
I don't know, I've never tried to fail over. The Elmah project is pretty solid, so I'm sure they've thought of that. You'll just have to dig.
Gavin Miller
+4  A: 

It seems that ELMAH can't trap its own errors

ELMAH does trap its own errors to some extent. If the ErrorLogModule encounters an exception while attempting to log the error then the exception resulting from logging is sent to the standard .NET Framework trace facility. See line 123 from 1.0 sources. See also the following walk-through from the ASP.NET documentation for getting the standard .NET Framework tracing working with ASP.NET tracing:

Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing

the AXD file isn't available when the SQL databse log fails.

That is correct. SQL Server database connectivity must be functional to view errors stored in a SQL Server database when using SqlErrorLog.

What is the intended behavior of ELMAH if the database isn't available?

If, for example, the SQL Server database is down, a SqlException will occur during logging. ELMAH will then send the SqlException object content to the standard .NET Framework trace facility.

How can I diagnose my errors if this occurs?

The best option here is to also enable logging and e-mailing of errors. If the database is down, chances are good that the mail gateway is up and you will still get notified of errors. The errors will, in effect, get logged in some mailbox(es). This also has the added advantage that if the mail gateway is ever down then chances are that the database will be up and errors will get logged there. If both are down, however, then you will need to seriously review your production infrastructure and possibly take measures for monitoring health of your system via additional measures.

Atif Aziz