When should I use Tracing vs Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

How to choose standard trace, Logger.NET, Enterprise Library, log4net or Ukadc.Diagnostics?

Is there a situation where one of them is more appropriate than the other? ... what would it be? (ASP.NET, console application, Azure Cloud, SOHO, Enterprise ...)

What are the advantages or disadvantages?

Did I miss any other basic logging frameworks?

+40
enterprise-library log4net system.diagnostics nlog
Jan 23 '11 at 17:24
source share
6 answers

There are many similar questions here on SO:

  • Registration of best practices
  • log4net vs TraceSource
  • Silverlight logging basics and / or best practices
  • log4net vs nlog
  • What is the meaning of cutting down the facade?
  • C # Logging. What should i use?

You have missed a few commonly used magazine frames. Here is a list of commonly used frameworks, some of which you have listed:

Registration of abstractions:

System.Diagnostics add-ons:

Other

A few other logging frameworks from codeplex (which I mentioned in SO already):

Why can you choose one over the other? It's a difficult question. This is largely a personal preference. This is partly a technical (or special) superiority.

One of the obvious drawbacks of any framework (especially third-party) is the quality of support. What if you have problems with log4net, NLog, Common.Logging, etc.? Can you get fixes from the developers of these frameworks? This may not be very important, as the source code is available for these platforms. However, you may prefer NOT to "inherit" the original tree just to fix or add the extension. I will say that frameworks are so extensible that many enhancements can be added through regular extension points.

If you read the links I posted above, I think it’s fair to say, based solely on the number of favorable references, that log4net will be a clear “winner”. This will be referred to more often as a historical favorite and something that many people will use in the future.

NLog has its own supporters, it just seems to have no top-level penetration or understanding, like log4net, although they are very similar. The capabilities of NLog are very similar to log4net, and it has the added benefit of having recently gone through a significant development cycle.

A corporate library is often touted as a good choice, but almost as often touted as a terrible choice. Maybe some of his negative reputation, maybe not very good early versions? Maybe better now?

System.Diagnostics is often recommended as a smart choice, with at least three strong advantages: no third-party dependency, many Microsoft components come with System.Diagnostics, it's easy to extend (presumably to add some features that are already present “for free”). within frameworks such as log4net and NLog?). If you use System.Diagnostics, I think that consensus will (like my recommendation) be using TraceSource objects, not Trace.WriteLine / Debug.WriteLine.

Also note that System.Diagnostics and WCF work well together. WCF message traffic can be logged using System.Diagnostics, and WCF will also distribute information about System.Diagnostics actions (System.Diagnostics.CorrelationManager.ActivityId) through the WCF service boundary calls.

I am not sure that log4net should continue to maintain its most preferred status. As noted here, in SO, log4net does not seem to be undergoing much development recently (note that I think “log4net is dead” is an exaggeration), while NLog 2.0 is currently in beta versions and a final release is expected in Q1. 2011 (update: NLog 2.0 was released on July 17, 2011). Does this make NLog a clearly better choice than log4net? I don’t know, but I think that, relatively speaking, NLog should get at least the same attention when choosing between the two and probably should be the intended favorite for the new development, at least until the development of log4net shows more signs of life.

log4net and NLog offer very flexible configuration options. They allow you to have very fine granularity in the definition of your registry operators (according to the "standard" registrar definition scheme for each type). They also make it easy to expand libraries, allowing you to create your own "log destination" objects (log4net Appenders and NLog Targets) and "formatting" objects (log4net and NLog LayoutRenderers template converters).

In addition to choosing a logging structure, some (many?) Advocate isolating your application code from being highly dependent on a particular logging environment using an abstraction layer. This can take the form of your own ILogger interface, which you are implementing, perhaps on top of an existing framework. In the future, you could change the wireframe by implementing your ILogger in a different wireframe. Or you can use DI / IoC to add "ILogger" to your code. Many DI / IoC infrastructures provide a built-in ILogger abstraction that can be configured to use log4net, NLog, or Enterprise Library, or you can write your own ILogger implementation and implement it). Who cares about implementation? Another way to isolate your code from being highly dependent on your particular logging environment is to use an existing logging abstraction framework such as Common.Logging or SLF. The advantage is that, again, your application is independent of the specific logging structure. However, some will say that you just exchanged one dependency (on the logging framework) for another (logging abstraction framework).

Two more notes about registering abstraction:

  1. A good logging abstraction should allow you to capture output from different logging frameworks in a single output file. Common.Logging calls this the "bridge." Suppose you wrote an application using Common.Logging, supported by NLog. Now say that you are using a third-party class library that is written using log4net directly. Using the bridge system, you can capture the output of log4net (through a custom application) and redirect it through Common.Logging so that the output of the library logs of third-party classes can be viewed in the context of the output of the logs of your application.

  2. Using the abstraction of logging also allows you to test log frames at design time. You might start to think that log4net is that way, but you want to leave yourself open to an NLog attempt. Using the abstraction of logging, it is relatively easy to switch between them. Ultimately, you can choose which logging framework, but at the same time, you could write a lot of code that does not depend on a particular logging framework.

Another reason you can choose one framework instead of another is the environment in which you work. If you are already using the Enterprise Library part, this may be enough to encourage you to use Enterprise Library logging.

What if you are developing in Silverlight? You can use something like Clog - part of calcium . You can also use NLog 2.0, which is compatible with Silverlight and WP7.

Addons System.Diagnostics (Ukadc.Diagnostics, Essential.Diagnostics). These are not journaling frameworks per se. Rather, they are collections of useful objects and extension points that can be used with the existing System.Diagnostics platform. In my opinion, one of the best things that each of these add-ons adds is the ability to format the output of the logs, just as you can format them using log4net and NLog. I did not use Essential.Diagnostics, but I experimented with Ukadc.Diagnostics and I think this is really cool. It’s even easy to write your own “formatting tokens”.

I don’t know if this fully answered your question (which is broad enough anyway), but I think that there is a lot of food for thought.

+98
Jan 23 2018-11-11T00:
source share

I just started using log4net in VS2010 and found that it has a dependency on System.Web ... which makes it incompatible with the ".NET xx Client Profile" framework ... Given that someone here posted about Windows Update using the client profile as a redistributable .NET option, this means that log4net can no longer be the login of choice if you want your code to work on most machines ...

Thanks for the info on the other parameters - I will check them ...

+5
Mar 02 '11 at 17:30
source share

Just add a few things extracted from the Microsoft Build 2013 conference:

  • Log4NET writes a file under heavy load, mainly because this process is synchronous. In certain conditions, you can get competition and timeouts. This can be verified using AppDynamics or any other similar tool.

  • NLog does not implement the sequence, so IO calls flow under load.

  • According to Microsoft, ETW uses ring buffer buffers that are highly efficient ..NET 4.5 and the event log structure combined with the Bock Net Application (AKA SLAB) will make this much more efficient.

+3
Aug 09 '13 at 7:14
source share

I am not a fan of log4j or log4net. I like the java.util.net logging mechanism, and therefore, for the most part, I recreated it in a github project called NetLog at https://github.com/greggwon/NetLog/ . Feel free to provide feedback. I have been trying for some time to establish a configuration based on the ConfigurationManager in the logging.properties file. Using java.util.logging, it was always easy enough to use command-line property options to indicate where the log was located. This is much more painful with .net if you are not using ConfigurationManager. Providing CM support will open the door to some different relationships between registrars and handlers that can improve some things.

NetLog includes an EventLogHandler, which will be logged in the system event log. It also has a Level.EventLog level set just below the “warning”, which allows you to have a named “level” to target an EventLog without using “WARNING” or “SEVERE”. I also have a TCPSocketHandler that allows you to connect to “logging” so you can have a “tail” in windows, without having a “tail” program.

+1
Aug 08 '13 at 23:28
source share

Take a look at the NetLog.Logging package on GitHub, this is my creation. It has a monitoring application, and follows the java.util.logging API paradigm, because this is what I like to use. He has a direct lock to access the “record”, and the lock holder records all the records in the queue, up to the limit, before moving on. This will allow keeping a journal to a lesser extent on the basis of competition I / O and provides a good compromise.

0
Dec 30 '14 at 19:00
source share

For some reason, System.Diagnostics does not support a way to redirect the entire trace to a single listener. If you want multiple sources to be directed to the same listener, you need to explicitly specify each source by name.

In a large system with many dependencies, you may not know all the sources, and you probably don't care. You just want the output to show what happens under the covers. To customize listeners for each source, using System.Diagnostics is significantly more difficult in large systems.

log4net not only supports the root level loader (listener), but also supports hierarchical logging, which allows you to configure logging for a logical set of sources as a group. In my opinion, this makes log4net a clear choice.

0
Dec 14 '16 at 17:19
source share



All Articles