Original reference http://msdn.microsoft.com/en-us/library/dn440731 (v=pandp.60). aspx
First, Introduction
Logs typically meet two main requirements: 1. Monitor application performance and provide information. In terms of performance, logs can monitor what's going on inside the program and sometimes monitor what's going on outside the program. 2. More importantly, it is used for auditing. This log tracks the user's behavior and records a series of tasks, read and modified information, and access to resources performed by the user.
The log module is a highly flexible and configurable solution that allows you to create and store log information in a variety of locations, classify and filter information, collect contextual information during debugging, audit trails, and record it in a flexible and diverse manner.
Second, what can the log module do?
The log module allows you to separate the logging functionality from the application code. It can send log entries to the Windows event log, database, text files, or messages that contain log information, Windows message queues, and so on. You can also customize the sending purpose.
In an application, simply generate a log entry with the appropriate object (such as LogWriter) and then call its method to write the log entry to the appropriate target location.
Figure 1-an Overview of the logging process and the objects in the logging block
Iii. the cost of the log and additional contextual information
No matter how the log is implemented, it always has some performance implications. The log module provides a flexible, highly configurable log solution and is carefully designed to minimize performance impact. However, you still need to know the impact and to consider how your log scheme will affect it and need to balance the requirements.
LogWriter automatically collects contextual information such as time, application, machine name, process ID, and so on. To minimize the performance impact, the LogWriter class caches these values and employs a delay minimization-that is, it is created only when it is actually used by a listener.
However, the cost of collecting additional contextual information is very high and wastes valuable resources, which can affect performance. Therefore, when you create LogEntry, the log module collects only when you specify that some infrequently used information is required. The four classes in the log module can collect specified contextual information, including COM +, current stack, run-time security-related, and system security-related. LogEntry also has a dictionary property that allows programmers to add information.
Iv. How to use logging Block?
The key is to create a log entry and then invoke the method to write the log entry to the target.
1. Add Loggingblock references to the project
You need to add a reference that has Microsoft.Practices.EnterpriseLibrary. Logging.dll if the log Microsoft.Practices.EnterpriseLibrary. Logging.Database.dll and add the required references: