Configure Error Logging Middleware (ELM) - in ASP.NET Core

As we discussed in our previous articles Elmah is most popular and easy to implement exception handling module for .net application. After launching, open source elmah library won't get updated. The current elmah library will not work as it's based on Asp.Net 4.x's modules and Handlers. Using ELM prototype you can capture unhandled Exceptions as well as logging. You can install Error Logging Middleware either from Package Management Console or Nuget package manager.
Install via nuget
PM> Install-Package Microsoft.AspNetCore.Diagnostics.Elm
or install through
"dependencies": {
"Microsoft.NETCore.App": {
  "version": "1.0.1",
  "type": "platform"
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Diagnostics.Elm": "0.2.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
After successful installation, let's configure Error logging Middleware in startup.cs class.Open Startup.cs class and locate a ConfigureServices method to register Error logging middleware using AddElm() extension method.
public void ConfigureServices(IServiceCollection services)
   // Add framework services.
     services.AddElm(options => {
   options.Path = new PathString("/elm");
  options.Filter =(name, level) => level == LogLevel.Error;
LogLevel enum defines logging severity levels. Following are the LogLevel type that you can set while setting up ELM.


Logs that contain the most detailed messages. These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.


Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.


Logs that track the general flow of the application. These logs should have long-term value.


Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.


Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure.


Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.


Not used for writing log messages. Specifies that a logging category should not write any messages.
Once the service is configured, navigate to Configure method to add below codes. Here, app.UseElmPage()  will setup elm page url and app.UseElmCapture() will adds ElmLoggerProvider.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)


    app.UseMvc(routes =>
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");


ELM page have option to filter the logs based on error, warning, information and other parameters.
Happy Logging! 😊


Popular posts from this blog

12 opensource and free MVC gridview contols

Scheduling background jobs using Hangfire in ASP.NET Core

Difference ExecuteNonQuery vs ExecuteScalar vs ExecuteReader in