Seven in the isline framework series of ASP. NET Enterprise Development Framework-applogprovider log framework (I)

Source: Internet
Author: User
Tags log4net
Logs and exceptions

After the system is deployed, the administrator needs a powerful log system to diagnose and fix configuration problems. This requires a set of configuration-based log record change methods. Experience shows that the Log Module is often an important part of the software development cycle. aicken has used log4net for a while and log4net is a good log framework, however, sometimes it still seems a little difficult. For example, you need to use different types of logs to record the behaviors of different classes and methods and different business behaviors. Sometimes, during system runtime, changes the record media or whether or not to record a Service Log. In this case, log4net may need to modifyCodeThe applogprovider module of isline framework can only modify the configuration file to meet the requirements. It has the following advantages:

    1. It provides applicationsProgramAccurate runtime environment for developers to find bugs in applications as soon as possible;
    2. Once the log output code is added to the program, logs can be generated and output during the program running without manual intervention.
    3. Different log information can be output to different places (such as the console, files, and databases) for future research.

These two providers are developed based on these needs. They are responsible for recording the running logs and runtime exceptions in the system, but the applogprovider of the isline framework is more flexible and easy to use than log4net, the advantages of this module are as follows:

    1. The render component defines the output media. As shown in the name, these components attach them to the log component and pass the output to the output stream. You can appender a component to multiple log objects.
    2. Flexible control of the log level. After the system is deployed, you can use the level control to quickly switch whether to record the information of a service block.
    3. By setting the log cache, the system collects logs and exception information of resources in a centralized manner. When a threshold value is reached, the system can efficiently write data to the storage media.
    4. Through the configuration file, you can quickly change the log recording media (files, databases), record the technology used, without changing the program file, you only need to change the configuration file.
    5. Users can precisely control the output of log information, reducing unnecessary information and improving log record performance. In addition, with the external configuration file, you can change the log behavior of the application without re-compiling the program, so that you can flexibly select the information to be recorded based on the situation.

Among the two providers, there is a very important concept: "render", which is the configuration node of the log exception module, it determines the target, record method, path, and other information of the system log record. The information can be obtained through configuration. It can be a database, text file, XML file, or even a TV set, however, apart from the built-in render of databases and files, other record media must inherit related interfaces and then expand the implementation.

Currently, this Provider supports the recording of SQL Server, Oracle, and text files. You can use SQL statements or stored procedures as recording methods.

RenderIntroduction:

This is a render instance.

 

  <Oracleusingsprender>  

<Appenderstyle>Oracle</Appenderstyle>

<Appendertype>Storedprocedure</Appendertype>

<Appenderinf>Isline. Data. configuration. oracleconnectstring</Appenderinf>

<Appendercontent>Sp_add_ilfwlog.add_ilfwlog</Appendercontent>

<Layoutinf> </Layoutinf>

<Level>Debug</Level>

</Oracleusingsprender>

 

 

<Oracleusingsprender> </oracleusingsprender> is a render node with the render name in brackets. The default render includes:

Oracleusingsprender

Use the stored procedure log of the Oracle database

Oracleusingtextrender

Use SQL statements of the Oracle database to record logs

Sqlserverusingsprender

Use the stored procedure log of the SQL Server database

Sqlserverusingtextrender

Use SQL statements of the SQL Server database to record logs

Filerender

Record logs to text files

Mailrender

Send Logs to recipients

Render includes four parts: appenderstyle, appendertype, appenderinf, appendercontent, and level ).

"Appenderstyle" indicates the logging method, which can be databases, files, etc., which is an enumeration type;

"Appendertype" indicates the Attachment Form, which can be a file or a stored procedure name.

"Appendercontent" indicates the record content. When appenderstyle specifies that the stored procedure is specified for the log record media and appendertype, "<appendercontent>" indicates the name of the stored procedure, and "appendertype" indicates the SQL statement, "<appendercontent>" is a specific SQL statement.

"Level" indicates the record level. When the level is smaller than the global log level, the log instance does not work. The Global log level is configured in Web. config, which is described below.

"Appenderinf" indicates the record path or the extended program used;

In the ilfw framework, by setting the configuration file, each log object is assigned a log priority level, that is, the value in the level node, at the same time, the configuration file also contains a global key value string. When the enumerated value in the level node is smaller than the global level, this log object will not be recorded.

The level information is as follows:

Level name

Explanation

Priority

All

Information of all instances will be recorded

Lowest

Info

 

 

Warn

 

 

Debug

 

 

Error

 

 

Fatal

 

 

Off

No instance information is recorded

Highest

The global configuration in Web. config is as follows:

<Add key = "isline. applog. configuration. Level" value = "debug"/>

Render greater than or equal to this level will be recorded, off> fatal> error> debug> warn> info> All


Figure 1 render Model

Isline. applog. applogprovider namespace:

The namespace consists of nine class libraries, including configuration, function, and enumeration. The basic class relationships are as follows:


Figure 2 Basic class relationship of applogprovider

 


Figure 3 basic class relationship of applogprovider

 

Figure 4 predictionprocessprovider basic class relationship

 

The namespace provides the ability to record system behavior to the media in the previous volume logic. The upper-layer business can record the current breakpoint behavior by calling the writelog () method.

Before calling this method, you must obtain the log entity in advance and pass it as a parameter to the preceding method. The log entity standardizes the recorded content. The log model is as follows:

 

Figure 5 LOG model

This model defines six log fields, which correspond to the database or other appender. When the applogprovider obtains the log entity, it loads the render module and renders the basic log information.

By loading configuration information such as record media, attachment mode, attachment format, and report level, render writes logs.

To be continued

I amAicken)Welcome to my next articleArticle.

Related Article

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.