Objective
When we do enterprise management system, there are more or less the integrity of the data requirements, such as the requirement that the system can not physically delete records, the requirement to add each data to have a system record, or update a piece of data need to track changes to the content, or delete the data need to record who deleted, when deleted, In order to be deleted by mistake, the system's XXX function can be used to recover the data deleted by mistake.
I call this function a log of operations
Why do you want to do the operation log?
In fact, the above also describes some, its main purpose is to track each user in the system operation behavior, such as data query, add, edit or delete even login behavior. Further understanding can be said to the user's use of the system situation tracking, the data tracking to prevent accidental deletion of data, change the record, some basis for the restoration of data, from some program can protect the integrity of the data.
System Design
Scene
We now have a table called Employee:
Id |
Int |
Name |
nvarchar (50) |
Gender |
nvarchar (2) |
DateCreated |
Datetime |
CreateUser |
nvarchar (50) |
There may be employeeedit.aspx (actions such as adding or updating employee information), employeelist.aspx (used to query or delete employee information) in the ASPX page
OK, now we want to make a system log of the information of the empoyee table operation, what should I do?
Maybe you can build one more table that's exactly the same as the Employee table, called employeelog:
datetime
int |
nvarchar () |
|
nvarchar (2) |
datecreated |
nvarchar (+) |
logcreated< /span> |
datetime |
| >operationtype
int |
There are some additional information such as logcreated(log add-on date) and operationtype(query, add, delete, update)
At this point, it is possible for everyone to log the user log is a very common event.
But...... The question is, what if I need to log the table employeeincome(employee's income)?
Good to set up a table called Employeeincomelog to record the employee's income status of the Operation log.
What if you need to log records of table Fixedasset(fixed assets)?
Well, you may realize that we do this not only to increase the number of tables, but also greatly increase the workload and development time, difficult to manage the database tables and so on.
So we need a log management that can do the above functions through simple configuration and writing.
Database design
Includes three tables,
Logsetting (Log settings)--Used to store configuration business table name, business name, primary key, etc.
Logsettingdetail (log setup details)--used to store the details required to configure the business table, such as the employee table, we may need to record the field name, gender and other information.
Logoperation (Operation log)--used to record the user's content on various business operations.
The next chapter will discuss how to implement the function of log management with code, let's take a few pictures below:
Log list:
To view the contents of a log:
System operation log Design (GO)