📜 ⬆️ ⬇️

Convenient error monitoring in an ASP.NET application

Hello, dear readers Habr. In this post I want to tell you about the module for monitoring errors in ASP.NET - ELMAH (Error Logging Modules and Handlers).

What is this useful for?


Imagine a situation where you have a website working in Prod mode with a large number of users performing various business tasks. From time to time, some users report spontaneously occurring errors that cannot be reproduced on the Dev environment. It is very difficult to understand from the description of the user what may be the cause of the error and at what combination of actions it occurred.

In this situation, it would be convenient that when an error occurs, details about it are automatically stored on the file system or in the database. In order to come to work later, we could open the log and view the entire list of excursions with the glass trace and other useful information. Elmah just provides this functionality.

First I want to show how the list of all errors and detailed information on each of them looks.

List of all errors:



')

Detailed description of each error:


(The page is big enough, so here's the link )

How to add all this to your site now:


Thanks to dependency injection, you can very easily connect all the functionality to an already working site without having to modify it. For this you need:

  1. Add the Elmah.dll library to the project.
  2. Add configuration options to web.config.

The library itself can be found at the link to the official website at the bottom of the post. Next, I will describe the minimal changes in web.config necessary for intercepting and displaying errors in the log.
  1. Add parameters to <configSections>:

  2. Add a section to <httpHandlers>:

  3. Add a section to <httpModules>:

  4. You also need to specify where the errors will be saved - to do this, add a section in the <configuration>:


    If you need to use the database instead of the file system, do this:



Done, now all errors that occur on your site will be available on the page: http: //server/elmah.axd

Of the useful features, I would also note:
  1. Support SQL Server, Oracle SQLite, MS Access.
  2. Filters unwanted errors (such as authentication errors).
  3. RSS lists of errors.
  4. Posting bugs on Twitter.
  5. Support for user exits (you can call the library method by submitting your own access to the input and it will go to the general list of errors)


If you want to play a little, here is a simple example of a site with Elmah connected:
tr.im/elmahtest

For those who want to seriously use Elmah, I recommend to visit the official website. There are source codes, binaries and documentation: code.google.com/p/elmah
And here is a detailed description with examples: dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx

Thanks for attention. I hope for someone this post will be useful :)

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


All Articles