9-exceptionprocessprovider exception framework of ASP. NET Enterprise Development Framework isline framework series (I)

Source: Internet
Author: User

Link

Isline. exceptionprocess. exceptionprocessprovider namespace:

System logs and system exceptions are recorded separately. ilfw processes system logs and exceptions separately to improve system flexibility and security. Predictionprocessprovider is an applicationProgramThe main component that requires interaction. It is used to generate exception messages. The generated exception messages are not directly displayed and will be output only after formatting by layout in advance.

Overview: 

The exception module is attached to isline. applog. applogprovider and exception modules are designed as special system logs. Therefore, the applog module must be configured first when the exception module is used. For details, see aicken.Article.

After configuring the Log Module, You need to introduce the namespace:

Using isline. exceptionprocess. exceptionprocessprovider;

Use the "add" label in Web. config to add an exception pointer:

<Add key = "isline. exceptionprocess. configuration. rendername" value = "oracleusingsprender"/>

This pointer indicates the Renderer used by the exception module. The Renderer name is value. When the module is loaded, isline is automatically loaded. the "Renderer initialization" module in the applog namespace loads the specific exception object only after the Renderer is initialized.

The configuration process is described as follows. If we need to record the exception information to the Oracle database and find that the exception is not so important, we only need to record it to a text file, so we need to modify the web. config file.

1. Add the following nodes between <configsections> </configsections>: 

Code

  <  Sectiongroup name  =  "  Isline. applog. Configuration  "  >  

< Section name = " Filerender " Type = " Isline. Data. configuration. suitconfig " />

< Section name = " Oracleusingsprender " Type = " Isline. Data. configuration. suitconfig " />
</ Sectiongroup >

2. Add the following nodes between </configsections> <etettings>:

Code

  <  Isline. applog. Configuration  >  

< Filerender >

< Appenderstyle > File </ Appenderstyle >

< Appendertype > Text </ Appendertype >

< Appenderinf > Islinelog / Log4net1.txt </ Appenderinf >

< Appendercontent > -& GT; Event Date: @ eventdate; -& GT; Level: @ level; -& GT; message: @ exception; -& GT; Source: @ source; -& GT; stack trace: @ stacktrace -& GT; trigger: @ trigger; -& GT; memo: @ message </ Appendercontent >

< Layoutinf > </ Layoutinf >

< Level > Debug </ Level >

</ Filerender >

< 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 >

</ Isline. applog. Configuration >

 

3. Use <add key = "isline. exceptionprocess. configuration. rendername" value = "oracleusingsprender"/> in Web. config to specify the log model for abnormal use. "Oracleusingsprender" is the name of one of the two log models we specified in step 1. Now all the exception information in the system is written to the media described in the "oracleusingsprender" model.

At this moment, the boss suddenly said that the exception does not need to be recorded in oralce, so you can record the text file. Well, we only need to change the name of the exception Renderer, change "oracleusingsprender" to "filerender", so that exceptions in the system are automatically redirected to text files. The path of the text file is described in the "appenderinf" label, and the record content is described in the "appendercontent" label.

 

System exception records

The namespace records the exception information in the system. the "exception" Object in. NET is directly thrown to exceptionprocessprovider. The provider automatically converts the exception type to the "logentity" mentioned earlier and writes it to the corresponding media, the corresponding media and other information can be the same as the log node, or you can use a separate node without affecting each other.

The usage of another standard predictionprocessprovider is recommended. As mentioned above, during system design, I usually establish a business entity model, business event model, and business message model in advance, the business entity model includes the business model and exception model. The design of the exception model is completed in the system design phase. It pre-defines possible errors during system operation and creates models for these errors.

Each custom exception model must inherit the exceptionentity base class and implement the iexceptionprocess interface. This not only quantifies system exceptions, but also effectively manages system exceptions and enhances system security. When the exception module is called at the upper layer, you do not need to use the writelog () method. When a catch detects a system exception, the exceptionprocessprovider automatically blocks the exception and enters the process of the ilfw exception module.

The isline framework currently supports two exception record modes:

    1. An error occurred while using the ilexception class.

This method is the simplest method. After simple information configuration of Web. config, you can directly intercept and record exceptions in the program, but the disadvantage is that you need to traverse various exceptions. This methodCodeAs follows:

 

Code

  Try  

{

String I = " I " ;

Response. Write (I );

}

Catch (Exception ex)

{

Ilexception Ile
= New Ilexception ();

Ile. writelog (Ex );

}

2. Use custom exception to record exception information

 

The custom exception record method is a standard OOP principle. You need to quantify each exception in the system design phase and model these exceptions. All model classes must inherit the ilexception class, and implement the writelog () method.

The implementation of the writelog () method can directly call the writelog (Ex) Implementation of ilexception within the exception class, which is very simple.

Then you can use the following code to use this exception management module:

Code

  Try

{

StringI= "I";

Response. Write (I );

}

Catch(Ilexception ex)

{

Ex. writelog (Ex );

}

 

Because exceptions are defined in advance, the system does not have to traverse the exception tree. Therefore, this method has high performance and embodies the principles of abstraction and encapsulation.

 

Not finished. To be continued

I amAicken) You are welcome to follow my next 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.