18

Is it possible to configure ELMAH with ASP.NET vNext? If so, how?

I am lost as to where even start, given there's not even a web.config anymore. If anyone has or can figure it out, please share with us.

Thank you

Eilon
  • 25,582
  • 3
  • 84
  • 102
georgiosd
  • 3,038
  • 3
  • 39
  • 51

1 Answers1

18

ELMAH does not work with ASP.NET 5 because ELMAH (given its name) is based on ASP.NET 4.x's Modules and Handlers (the "MAH" of "ELMAH").

In ASP.NET 5 the replacement for modules and handlers is called middleware.

There is a prototype in ASP.NET 5 called "ELM" (Error Logging Middleware) that has some features similar to ELMAH. You can check out a sample here: https://github.com/aspnet/Entropy/tree/dev/samples/Logging.Elm

Eilon
  • 25,582
  • 3
  • 84
  • 102
  • Hm... this looks more like a replacement to NLog/Log4Net than for ELMAH. i.e. more generic logging vs unhandled exceptions. – georgiosd Mar 08 '15 at 00:36
  • I'd say ELM is closer to what ELMAH is trying to do (though ELMAH has way, waaay more features). ELM captures all exceptions in an app, as well as all logs from the new `ILogger` interface, and shows them in a searchable/filterable web page. The `ILogger` interface is sort of closer to log4net. – Eilon Mar 08 '15 at 00:39
  • how does one secure the ELM page? – georgiosd Sep 29 '15 at 16:29
  • 1
    @georgiosd you can put authentication middleware in front of it to add any required authentication and authorization. You'll need to "fork" the middleware pipeline using `app.Map()` or a similar API, and put the ELM-specific auth middleware and the ELM page in that fork. Then the rest of your app will be on the "main" middleware pipeline with whatever other middleware you have there (e.g. Routing/MVC, diagnostics pages, etc.). – Eilon Sep 29 '15 at 16:37
  • @Elion thank you for the prompt response - do you mind adding an example? My head hurts from reading that, took me two weeks to understand Github forking :) – georgiosd Sep 29 '15 at 17:04
  • @georgiosd sorry I don't have an example available for ASP.NET 5, but I found an example using a previous version: http://aspnet.codeplex.com/SourceControl/latest#Samples/Katana/BranchingPipelines/ReadMe.txt Most of the APIs are the same or similar, so it shouldn't be too hard to get it working. – Eilon Sep 29 '15 at 17:58
  • Thank you @Elion, I'll see if I can work it out and create a sample. – georgiosd Sep 29 '15 at 19:04
  • Is there an option to store the information in a database? – Juan Oct 14 '15 at 16:52
  • @Juan a custom log provider can store the information anywhere it likes. – Eilon Oct 14 '15 at 19:38
  • @Eilon thanks I will look into that. If anyone have or create an example and want to share it will be appreciated :) – Juan Oct 14 '15 at 20:36
  • So know that web config is back in asp net core and you can put a moniker for net46:{} I wonder if elmah wokrs with asp net core. I will test this week but you should too. – hidden Jul 08 '16 at 17:36
  • @hidden it will not work because web.config in ASP.NET Core is used only for IIS settings, not for any ASP.NET settings. – Eilon Jul 08 '16 at 18:58
  • It's not hard to do error logging manually in ASP.NET Core, without ELMAH. See how to do it here: http://stackoverflow.com/questions/35092867/how-does-one-use-elmah-in-asp-net-5-vnext-core/38397916 – Rono Sep 12 '16 at 13:29