Error Log Processing

Source: Internet
Author: User
Tags log4net
Overview

Develop a MVC web program and release it. When users start to use our program, the corresponding error occurs during use and jump to the error page directly, the user asked us what was going on. We generally didn't know what was going on at the time. If we knew it, we changed it. So what should we do to quickly locate the problem and modify it?

Some people say that we can perform corresponding debugging, connect people's databases, get the corresponding version of the program, and then debug it. This is generally not feasible, the data of the launch program is the actual data (high security), and the permission control is very high. If you only perform debugging, you can obtain all the data of others, you will not do this for anyone else. So what should we do? At this point, the role of the error log has come out, it can help us quickly identify the problem, this is the topic of this blog: Error Log processing.


Error Log Processing Solution

Solution 1: for every possible error, we will write a solution to save it in the corresponding error file.

For every possible error, we need to write a piece of repeated code by ourselves. This is obviously not good. At least we should abstract it into a class.

Solution 2: customize an error handling class, inherit handleerrorattribute, and register it in global. When an error occurs in the program, it is thrown to this layer, the method will be automatically executed to achieve a global error handling effect. At this time, we will write the code written into the error file here to achieve global sharing.

The above method is not very good, because it can only be used to record errors. It is very troublesome to say that the error information is written to the database.

Solution 3: Use observer + spring.net to record multiple error logs.

The observer mode can enable many observer types. spring.net can create these types through the configuration file to achieve an OK effect by modifying some configurations.

The above method seems to be okay, but it is not. If a program with a large number of users has a small error, it will be infinitely magnified, that is, within the same time, if you use this program, and there are a large number of errors at this point, you need to write them to the error log or database. Then, the write process becomes very slow.

Solution 4: record the error information in the queue first, and then enable a thread from the thread pool to continuously retrieve data from the queue and perform write operations.

This solution greatly reduces the user's waiting time for writing error logs. However, there is still a problem. This problem can be said that the three solutions are left behind, that is, there are too many ways to record error logs. Have we all written them? If you want to write it all, this is indeed a small project.

Solution 5: Use log4net to record the corresponding error information. The log4net assembly is introduced in the program. Then, by setting the configuration file, we can record multiple error logs, the maintenance of these codes does not require us to write. It is a good word.


Summary

Error logs are not a part of your business needs.

Error Log Processing

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.