This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17865|Reply: 0

[ASP.NET] asp.net MVC global exception handling and exception logs

[Copy link]
Posted on 10/18/2016 8:44:49 PM | | |
In the Application_Start method in the MVC3 website global.asax, there is this piece of code



Its main use is to register global filters, which can be set in the RegisterGlobalFilters method, such as code:



Using HandleErrorAttribute to handle exceptions is simple, first enable custom errors in the Web.config configuration file, because the HandleError feature depends on custom errors, and the mode of customErrors must be set to On or RemoteOnly:




So except for the 500 error, other errors can only be configured by the custom error module to the response page:



After we have set up the above two pieces, if we want to record the exception log, then we need to improve the ExceptionLogAttribute class, look at the code:



As you can see, in the above class, there is a CreateVLog method, what is it for, in fact, it is our log function class, which can persist different types of logs, which I will explain in a separate lecture.

Today is mainly the recording method of global exceptions in MVC3, hehe.









Previous:C# performs secure traversal operations in a multi-threaded environment
Next:asp.net write appSettings to the file outside
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com