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:
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.
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.