ASP.NET MVC Global Error Handling with ELMAH - Best Practices

I really would like to integrate ELMAH into my MVC4 application, but I have a few problems:

  • if elmah redirects all errors to a page with a specific error, I only need to return success (for example, to update, delete, ...) to the user?

  • If elmah catches all errors, do I need to handle errors (e.g. use try catch ) in my code at all?

  • Is there a best practice example somewhere how to use ELMAH?

+1
source share
1 answer

1) Elmah does any redirects, so you yourself handle the error pages in web.config (this can be done here )

2) You must. Elmah is for reporting unhandled exceptions. You can log processed exceptions as follows:

 try { ..... } catch(Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } 

3) Good article on Scott Hanselman’s blog: ELMAH: Error logging modules and handlers for ASP.NET (and MVC too!)

+3
source

Source: https://habr.com/ru/post/1496613/


All Articles