Enterprise Library 6--using the Logging application Block2

Source: Internet
Author: User

Original Reference ? http://msdn.microsoft.com/en-us/library/dn440731 (v=pandp.60). aspx

First, Introduction

logs typically meet the 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.

LogWriterautomatically collect some like time, application, machine name, processIDand other contextual information. To minimize performance impact,LogWriterclass caches these values and uses a delay minimization--that is, only when aListenerIt is not created until it is actually used.
However, the cost of collecting additional contextual information is very high and wastes valuable resources, which can affect performance. Therefore, when you createLogEntry, the Log module collects only when you specify that some infrequently used information is required. The four classes in the log module can collect the specified context information, includingCOM +, current stack, run-time security-related, and system security-related. LogEntryThere is also a dictionary property that allows the programmer 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 in the project

references that need to be added are Microsoft.Practices.EnterpriseLibrary. Logging.dll, if the log is to be written to the database also reference ? Microsoft.Practices.EnterpriseLibrary. Logging.Database.dll

2 , Configuration Loggin Block

Configuration Logging Block You can use the method of code, or you can use the Configuration tool, which describes how to configure the tool.

Step1 : Start the Configuration tool. Run "EntLibConfig.exe"and click "file| Open " opens the configuration file for the target program (web. config or app. config), after opening the file 1 :

??

Figure 1

STEP2 : configuration. If the "Logging Settings" node does not appear in the left navigation bar , it indicates that the Enterprise Library log-related configuration has not previously been made, click "blocks| Add Logging Settings ", the figure 2 interface appears:

Figure 2

If you are modifying the configuration, right-click " Logging Settings " select "show/hide application Block Elements" (or click on the front triangle symbol) will also appear.

view figure 2 "Logging Filters" category (journal category), in the middle is listener (the carrier that holds the log file), to the right is formatter (log content formatter). A category listener listener corresponds to a

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.