12

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?

DotnetDude
  • 11,617
  • 35
  • 100
  • 158

1 Answers1

20

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/

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • 2
    A quick pointer. Serilog doesn't integrate with ELMAH. We (at elmah.io) offer a Serilog sink for elmah.io, but not other types of ELMAH error loggers. While elmah.io supports the severities from Serilog, ELMAH itself doesn't (and shouldn't do so either). – ThomasArdal Jun 08 '15 at 04:58
  • ELMAH supports manual error logging out of the box: http://blog.elmah.io/how-to-log-errors-to-elmah-programmatically/ – ThomasArdal Jun 08 '15 at 04:59
  • @ThomasArdal - that's still an exception handler, not tracing and event logging.. – Erik Funkenbusch Jun 08 '15 at 07:17
  • Exactly. ErrorSignal can be used to log manually, but only exceptions. – ThomasArdal Jun 08 '15 at 07:31
  • 1
    Elmah pulls the context and lots of nice variables such as the IP Address and other "Enrichers" as Serilog calls them. How do you get SeriLog to enrich with a bunch of stuff from HttpContext and Request data without all the hassle of writing your own? – Suamere Aug 30 '16 at 21:25
  • Can serilog catch unhandled exceptions? – Dblock247 Jun 04 '17 at 03:07
  • @Dblock247 - not by itself, but people have written various extensions to serilog to do this. One example: https://blog.getseq.net/instant-asp-net-diagnostics-with-serilogweb-classic/ – Erik Funkenbusch Jun 04 '17 at 04:21
  • 1
    @Suamere there are lots of extensions in nuget. try Serilog.Enrichers.HttpContextData for example – richardwhatever Apr 13 '18 at 07:52