TraceSource vs Enterprise logging block
Are there any specific uses cases where just using TraceSource will not be enough and one should consider looking in开发者_高级运维to other logging libraries ( like Enterprise logging block, log4net, NLog etc)?
A few reasons to use a logging library:
1. It provides functionality or flexibility that you need and saves development effort
You may want to use Enterprise Library if you want to log to:
- WMI
- MSMQ
- Database
I believe these are not supported by the .NET TraceListeners.
In addition if you want some rolling file behavior (e.g. new file every day or after certain size etc.) then that is also supported in Enterprise Library, log4net etc. With Enterprise Library, Message format can also be set at runtime via configuration so that adds some flexibility.
2. Developers may be more familiar with a common logging library rather than a custom approach
Most projects that I've been on have used a logging library of some sort.
3. It can provide a level of abstraction over and above the built in logging functionality
The main benefit I've found to Enterprise Library logging is that it is very configurable. You can configure details for various logging categories, then change that as necessary, in Production.
For example, your standard Production configuration might be to log only error level information to the Windows Event Log (perhaps because you have some monitoring software watching the event logs). You might configure logging of warnings, or informational messages, but have those turned off by default. When necessary to see that information in Production, your Operations staff can simply enable those categories for long enough to diagnose the problem.
Another benefit is that it provides for remote logging, either by logging directly to a database, or by logging to a remote agent over an MSMQ queue. This permits logging to be centralized, at the same time as making it reliable by using the queue.
精彩评论