In the development program, the error log is necessary. Add error logs to use today and log them for easy viewing later
Using the ASP. NET error handling mechanism
Application_Error
Paste the code
1 protected voidApplication_Error (Objectsender, EventArgs e)2 {3C:exception LastErr = Server.GetLastError (). GetBaseException ();//using the GetLastError method of the internal server object, the method returns an exception,4 Try5 {6 stringPath ="/error/"+ DateTime.Today.ToString ("YYMMDD") +". txt";7 stringMapPath = HttpContext.Current.Server.MapPath (path);//Specify the physical path corresponding to the virtual path using the MapPath method on the server side8 //if the path below the file does not exist9 if(!file.exists (mapPath))Ten { OneFile.create (MapPath). Close ();//Create a file below the folder, and close the stream to release A } - //strength file stream for writing - using(StreamWriter writer =file.appendtext (MapPath))//append to file using Apperntext the { -Writer. WriteLine ("{0}", DateTime.Now.ToString ()); - writer. WriteLine (Lasterr.Message.ToString ()); -Writer. WriteLine ("-------------------------------"); +Writer. Flush ();//cleans up the buffer and inserts the data into -Writer. Close ();//Close after writing + } A } at Catch(Exception ex) - { - GotoC; -}
ASP. NET Add error log