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