elmah.io - Logging Exceptions to the Cloud
Elmah stands for Error Logging Modules and Handlers is a great open source application logging utility for ASP.NET which is available for some time now. Some of the features provided by Elmah are given below.
- Logging Unhandled exceptions
- Provides a web page to view the logged exceptions
- Also provides a web page to view all the details of a logged exception
- Option to send an email notification when an error occurs
- RSS feed for the last 15 errors from the log
- Options for backing store for the log includes in-memory, SQL Server, flat file, Oracle, SQL Lite etc
Normally when we log exceptions we will keep the info in a flat file or in the database, but Elmah got another option which is to directly store all the logs in the cloud via elmah.io without much change to your existing framework.
Set Up elmah.io
First you need to create an account in elmah.io, it's pretty simple and even you can use any of social logins provided by Twitter, Facebook, Outlook or Google. Once you create the login, just create a log for your application from the dashboard. Just give a name for the log and click save. We will leave the other options for the time being. Also whenever a log is created, Elmah will create a unique id for the log, keep a note of it as we need it later when we configure it in our project.
Setup your project to use elmah.io
Now, in our project we need to add a Elmah logger by installing the following command in the Nuget Package Manager Console.
During the installation it will ask for the log id, please provide the one for the log which we created earlier in this prompt
When the package is added successfully, it will be listed under the References section in your project.
That's all we need to configure elmah.io in your project.
elmah.io in Action
To test the logging, let's run the application and try to navigate to page that is not existing in the application. The server will give a 404 response now and if you look in the log we just created in the elmah.io site, you will see a whole lot of information regarding the error.
If you click on an error, it will open up a pop over showing the detailed information regarding the error. This will have 3 sections for showing the detailed error information, the server variables present in that request and in the Fix section it will show you quick fixes for the problem if it's commonly occuring one. Even better it will also pull information from Stack Overflow for the solutions provided there for this by others.
This methodology is particulary useful when you want to track exceptions without making much change to existing code base and also it will also helps you to search and track the logs without even going into your hosting space. I will be writing more posts on it on customizing Elmah to your needs. Till then Happy Coding.
Breaking Changes coming your way for ASP.NET Core 3.0
Resilient Connections in Entity Framework Core