Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog, Elmah or both for a ASP.NET MVC project?

I implemented Serilog for a ASP.NET MVC project which will be hosted in Azure and Serilog provides sinks to log to Azure storage.

I then wanted a better way to handle exceptions and ran into this very informative article on integrating ASP.NET MVC with Elmah - http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx

I like it that Elmah lets you view exceptions and has ways to notify admins when exceptions occur. Given that I already have Serilog, should I replace it with Elmah or use it in conjunction with it?

like image 857
DotnetDude Avatar asked Jun 08 '15 03:06

DotnetDude


People also ask

What is Elmah MVC?

ELMAH (Error Logging Modules and Handlers) is a series of HTTP modules and an HTTP handler that may be added to your ASP.NET web applications for the purpose of tracking unhandled exceptions. ELMAH provides access to view these errors by way of a web console, email notifications. It is open-source error logging system.

Does Elmah work with .NET core?

elmah.io for ASP.NET Core supports a range of actions for hooking into the process of logging messages. Hooks are registered as actions when installing the elmah.io middleware: services.

How do you check Elmah errors?

Build the application, run it in the browser, and navigate to http://www.yoursite.com/elmah.axd. You are prompted to log in before you see the content. After a successful authentication, you see a web page to remotely view the entire log of recorded exceptions.


1 Answers

Elmah is only used to log unhandled exceptions. That is, exceptions that would otherwise result in a yellow screen of death. It has a very nice log viewer as well, but ultimately, it's only used for exception logging.

Serilog can do everything that Elmah can do, with the exception (no pun intended) of the built-in viewer. However, there are lots of ways to view your exceptions.

Serilog will also do tracing or "event logging", which Elmah won't do (by default, there are ways to use Elmah's infrastructure to do this).

Finally, you don't get the structure of Serilog's logging with Elmah. You just get flat logfiles.

You can use both if you want, but I'd rather just configure an Exception handler to log to Serilog.

FYI, Serilog can log to Elmah.

http://blog.elmah.io/logging-to-elmah-io-from-serilog/

There's a good blog entry on the Elmah website about the difference between Elmah and Log4net. Many of the same reasons apply with Serilog, although obviously there is also Serilog's structured logging which you wouldn't get with either of those.

http://blog.elmah.io/elmah-vs-log4net/

Also, despite the fact I've linked to elmah.io, don't be confused. There are two versions of Elmah. One of them is free (and open source), the other is not (although it is partially open source). Elmah.io is cloud based, and not free. Elmah is still open source and free.

http://code.google.com/p/elmah/

like image 125
Erik Funkenbusch Avatar answered Oct 05 '22 06:10

Erik Funkenbusch