The Logging Application Block in Enterprise Library 2.0 is Logging and Instrumentation Application Block in version 1.0 because it focuses on logging and Renamed as Logging Application Block. Logging Application Block provides a unified logging feature that supports writing logs to multiple destinations, such as: 1, databases, 2, text files, 3, email;4, message queues, 5, WMI event;6, event logs, 7, custom zones ( For Example:xml File), and so on.
Logging Application Block provides a unified interface for writing logs to any given destination, and we do not need to specify where the log information should be written in the code, but what happens in the configuration file.
Write the log and write down the log information, which means that the operator can change the logging behavior as well as our developers without modifying the code. It has the following advantages for our program development:
1, can make our application in the logging method to maintain consistent;
2, it is precisely because it provides a consistent structure model, to a large extent, it is convenient for us to learn from developers;
3, a good solution to the application of the log problem;
4, scalable, we can customize the log information filter procedures and format the log information program
... ...
Logging Application Block 2.0 makes the following changes relative to the previous version:
1, LogEntry objects can now belong to one or more categories (category);
In version 2 and 2.0, we can customize the filter to filter the information before logging Application Block sends the log information to the Listener (trace listeners), and the filter supports us to filter events based on the class and/or priority of the event. We can customize the filter to filter the event according to the standard filters.
3, you can in the code through the query filter to determine whether the current event needs to be logged, which greatly reduces the amount of log records, can effectively improve the performance of the application.
Let's just say a little bit about the use of logging Application block, you first need to add a reference to the following three assemblies:
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;
using Microsoft.Practices.EnterpriseLibrary.Logging.Filters;
The same as the previous block, before using or first say the configuration method, first use the Configuration tool to open our program app.config/web.config, and then select the Application Right button, new-->logging application block, as shown below: