18

I have to write a centralized logging framework.

Basic requirements are:

  • Log exceptions as well as other details if needed to SQL Server DB.
  • If DB is down i.e. a failover option is to log to a file and email

I had done some reading around and looks NLog is the best option being simple and most features I need. My plan is to write a wrapper class library around NLog and use my library in all my asp.net applications, web api as well as other library projects and some classic asp sites using COM+.

But I noticed some people mentioning using ELMAH for exception handling and NLog for diagnostics.

My Question(or I should say confusion): Why would I use ELMAH if I am using NLog?

Or when would one use ELMAH alongside NLog?

Or

Note I am not trying to compare the features-by-feature but want to understand: What would be the scenario when one would opt for one over other? Except the fact that ELMAH is for web applications.

Julian
  • 33,915
  • 22
  • 119
  • 174
gbs
  • 7,196
  • 5
  • 43
  • 69

2 Answers2

17

Elmah is used for handling uncaught exceptions, and is generally a "last line of defense" to be able to identify when things go completely belly up. You can read what it provides on its github page: http://code.google.com/p/elmah/

NLog and others (I highly recommend Serilog) are used for runtime diagnostics and tracing... That is, to dump information which you are either tracing, or logging (which is, by definition, not uncaught exceptions).

NLog, as like log4net, nlog is getting quite long in the tooth and while there was a recent release... the previous release a year earlier, and I feel most of the "old guard" logging frameworks have not really grown with the times.

Serilog is a much better choice, as it provides "structured logging" which allows you to, for example, search on specific fields in the log files.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • But say if in the application_error in global.asax, I use NLog to log the error. Would it be considered equivalent to "handling uncaught exceptions" – gbs Feb 23 '15 at 05:08
  • 1
    @gbs - no, because Elmah handles things at the IIS HTTP handler level, which is further up the chain. Further, it also provides a nice web-based viewer for events, which nlog doesn't provide. – Erik Funkenbusch Feb 23 '15 at 05:55
  • Ok...but I think it will still be handling the Error event in those modules. I will have to look at the code itself. You are right that web-based viewer is definitely something that doesn't come with NLog. – gbs Feb 23 '15 at 17:16
  • @ErikFunkenbusch Nlog also provide structured logging and also can log exceptions. You just need a reference to logger in Application_Error. So what are the arguments for Elmah? – MSD561 Feb 21 '19 at 14:32
  • @MSD561 - Yes, you *can* log exceptions with any framework. Elmah's entire purpose is to do that, and provides a log viewer. You can do anything you want with any framework, it's your choice what to use. – Erik Funkenbusch Feb 21 '19 at 15:03
  • @ErikFunkenbusch Elmah solution seems to be for small projects. In today enterprise environment there is a strong need for centralized logging, with solutions like Stackify. – MSD561 Mar 04 '19 at 17:55
  • 1
    @MSD561 Certainly, Stackify and others like Instana are awesome products, but also highly expensive (if you have a lot of hosts). If you're looking for centralized logging for a reasonable price, Microsoft Application Insights is hard to beat. It can't do everything the more expensive tools can, but it's hard to beat for the price. – Erik Funkenbusch Mar 04 '19 at 21:39
-1

Erik hit it on the head as to why someone would use both. However, ReflectInsight is a much better choice for structured logging and exception trapping. https://insightextensions.codeplex.com

code5
  • 4,434
  • 2
  • 31
  • 24
  • 1
    ReflectInsight is commercial. Not really comparable to nlog, serilog, or others... – Erik Funkenbusch Feb 23 '15 at 05:57
  • Commercial yes, but at such a low price it pays off in just one day's work, alleviating all the limitations to all other open source solutions currently out there, IMHO. – code5 Feb 23 '15 at 08:01
  • 1
    That makes the assumption that you're a single developer. Let's say you're a company with 500 developers, any of which might work on the application... now you have to buy 500 licenses because otherwise you would have no idea who was and wasn't licensed. That's what's insidious about these kinds of libraries that you, the lone developer just do not understand... And, just because you're a big company doesn't mean you can just toss $150,000 at a library for such a single purpose. – Erik Funkenbusch Feb 23 '15 at 15:59
  • No not true. You only pay for the Viewer in this case. The rest of the Library is royalty free. If you want just the Log Viewer (not live) it's free. – code5 Feb 23 '15 at 20:29
  • You are required to pay the license per developer, according to the licensing faq. – Erik Funkenbusch Feb 23 '15 at 22:18
  • Yes, for the Viewer you do. I have my own copy of the Viewer. The API is royalty free. You can download it as a Nuget package without a license. For the most part we only log to Text and Binary files. But having the Live Viewer during development and in some cases production, is amazing but not required. But back to the original question, it real supports request based logging. It makes it extremely easy to find issues when you can see full execution paths via traceability and the level of data you log is insane. List of collections, objects, JSON, etc. – code5 Feb 24 '15 at 03:02
  • That's not what the licensing faq says, although for a faq its incredibly vague. It claims you are allowed to redistributes files that are explicitly listed in the license agreement, except that the license agreement does not explicitly list any files. It also says "ReflectSoftware does not charge any royalties for redistribution of libraries that have been integrated into applications which you engineer. Of course, this only applies if you have a valid license to all products which are being used within your application." – Erik Funkenbusch Feb 24 '15 at 04:13
  • In fact, I can find no reference to the license covering the viewer only anywhere on the site, or licenses. All it mentions is "product". – Erik Funkenbusch Feb 24 '15 at 04:14
  • Hmm... Let me check with them. I'll also ask ops as they requested we use this product. – code5 Feb 24 '15 at 04:26
  • 2
    @code5 are you not one of the developers of ReflectInsight? (Just reading your disclosure _"I'm one of the developers for ReflectInsight"_ on http://stackoverflow.com/questions/4293206/a-good-logger-for-net/22391521#22391521) - good etiquette to point out, especially when comparing RI to other options – Nicholas Blumhardt Feb 24 '15 at 21:40
  • (Not to be abrasive, sorry - just think it is an important piece of context here.) – Nicholas Blumhardt Feb 24 '15 at 21:46
  • 1
    @NicholasBlumhardt, I'm one of the developers of the product but I don't work for the company "ReflectSoftware" directly. How they Licence their product is not part of the company I work for interests - two separate entities. I was a bit confused about the license and ask the sales team about clarity. You only require a paid license for the Live Viewer which gives you a ongoing license for the Log Viewer. Their API to log data is free of charge no license required. They will make this less vague when they update their site. Since our company likes the product we now use it as well :) – code5 Feb 25 '15 at 01:57