Write your own C # framework (20) from scratch-framework exception handling and logging
Recently, I was very busy and had a lot of chores, so the development of this framework was also intermittent. I finally completed the previously set functions two days ago, and I found some minor functions missing before I found them again. The following sections mainly describe the small size of development based on this framework. In the future, a new solution will be provided if the code is updated, if not, use the source code released earlier.
This framework mainly has four types of log records: logon logs, operation logs, manual collection of exception logs, and automatic collection of exception logs. Most log collection tasks are not implemented by developers, the required logs are automatically recorded in the template and related function classes.
Login logs, of course, record the user Login, logout, online time logs, mainly in the Login (Login. aspx), back-end homepage (Main. aspx, with an exit button) and online list (OnlineUsersList. aspx, with the removal of user deprecation buttons) and several other pages for use. The logic-layer functions used are placed in LoginLogBll. cs (User Login log custom logic class) and OnlineUsersBll. cs (OnlineUsersBll logic class) files. The logon page mainly records the log information of the user logging on to the system, while other pages record the log information of the user logging out of the system and the online duration. Of course, the backend homepage has a timer that updates the last online time of the user every minute so that the user can exit the system (or directly close the browser ), relevant programs can record user exit information and online duration in a timely manner.
Operation logs record the time when a user opens the page in the backend management system, then, add, modify, delete records, Update Status, delete images, and remove users from offline ...... and other operation information. When a problem occurs, the management personnel can quickly find out whether the operator is responsible for the problem. It is also convenient for the leaders to check whether the backend personnel have used the system, analysis of the promotion effect of the system (Many OA or enterprise management systems, after the enterprise buys them back, many employees are reluctant to use the system, resulting in a system that has spent a lot of money to buy, of course, this operation record does not greatly help the improvement of this situation, but at least let the relevant personnel know the usage of the system, haha ...)
For operation log records, developers basically do not need to write code, because the generated template function has fully recorded various operation logs, unless the udfs do not call the ADD, modify, or delete functions generated by the template, use the SubSonic3.0 plug-in interface or ADO. NET interface, so you have to write your own code records. For records on pages that users have accessed, the pages developed by the backend system must inherit the PageBase class. When each backend page is opened, the initialization function of this class is run, the initialization function calls CommonBll. userRecord (this) function faithfully records user operation traces.
For specific implementation code, you can view the template function class generated by the logic layer. All adding, modifying, deleting, and updating functions in the template class will call UseLogBll. getInstence (). the Save () function records the operations performed by the user. If a user-defined function wants to record user operation instructions, you can directly call this function and write the User-Defined operation instructions.
Manually collect exception logs. for exceptions, some friends suggest throwing them out so that they can easily find bugs and fix them. However, if they are all handled in this way, the user experience will be poor, therefore, I usually use the data layer to throw exceptions, capture them both at the logic layer or UI Layer, and then call CommonBll In the catch Block. writeLog ("exception description", e) records the exception to a file. When the system delivers the exception to the user, the user performs some operations, in case of an exception, it only shows failure or operation failure, but does not throw Yellow Pages. When maintenance is required, you only need to package the Data folder under the software or website root directory to the developer to analyze and view the exception.
Of course, for programs that require very detailed log records, you can also record the execution results of each step by calling the log function to help developers analyze problems.
For manual collection of abnormal call code, you can view the template class and UI Layer Code under the SubSonic folder of the Logic layer (Solution. Logic. Managers.
Automatic exception log collection, as its name implies, automatically records all exceptions that we have not captured. Although we have done exception capture, but it is inevitable that some places will forget to capture, so we will record it in global exception handling. We are at Global. the Application_Error () function of the asax file collects exceptions, collects all exceptions on the server page, and calls the custom function ErrorLogBll. getInstence (). save () records them to the database.
Based on the above four types of log records, the information we need is basically recorded to help us troubleshoot security problems and various errors.
Solution download: (this solution forgot to open the previously commented-out permission... and then resend it after the next processing)
Start from scratch and write down the final solution of the entire cve-rar framework.
Note: If you have tried to use the database in the previous test example for solutions in all the chapters, the list cannot be displayed, so after checking it, you will know that the database has no records ...... so here, I will add and modify data tables or fields as needed during the development process. In order to avoid writing too many SQL statements, therefore, the databases configured in each chapter only correspond to this chapter. When you use the new solution, you can re-append the new database. When you open the data dictionary, you will see that I have recorded almost every modification to the data dictionary for your convenience.
Copyright:
This article was originally published by AllEmpty and published in the blog Park. You are welcome to repost it. You must keep this statement without your consent and provide the original article link clearly on the article page,Otherwise, the right to pursue legal liability is reserved.. If you have any questions, you can use1654937@qq.comThank you very much for contacting me.
As long as you are interested in learning and making progress together, you can add Q group: 327360708 to this topic.
For more information, please refer to blog: http://www.cnblogs.com/EmptyFS/