0

I'm new to Elmah and considering implementing it in a project. It would be an ASP.NET MVC + Umbraco + EF web project which will have multiple layers (Business, DAL etc).

My interest in Elmah is its ability to handle unhandled exceptions.

But the question is does it handle unhandled exceptions from other layers (Services, Business, DAL etc) as well or just from Web layer (ASP.NET MVC) ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user576510
  • 5,777
  • 20
  • 81
  • 144
  • 1
    Yes. I believe ELMAH (and similar frameworks) add a handler for `AppDomain.UnhandledException`.. which is across the whole `AppDomain`. – Simon Whitehead Sep 10 '14 at 02:04
  • ELMAH is a great tool - but really, it doesn't *handle* the exceptions - it just records them and makes the details available for later inspection. If you want to really *handle* an exception (and do something about it, e.g. retry or something else) - it's still up to you to do this – marc_s Sep 10 '14 at 04:54
  • My understanding was that elmah needs the httpcontext to get the exception details. So it would only log exceptions from other layers if they are thrown. – iceburg Sep 10 '14 at 06:09

1 Answers1

2

ELMAH handles any exception thrown back to the client. This means that exceptions thrown in your data layer do not get logged, if you catch them in the MVC layer or anywhere else. You typically don't want exceptions from lower layers to end up at the client.

ELMAH also supports manual logging of errors through ErrorSignal like this:

try
{
    database.DoSomeStuff();
}
catch (SomeDatabaseException ex)
{
    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
Gareth
  • 5,140
  • 5
  • 42
  • 73
ThomasArdal
  • 4,999
  • 4
  • 33
  • 73