Log tracking in the EF Entity Framework is usually done by writing a log entity class and verifying the property's original value when the data is saved for log tracking. Of course, you can also use some third extension libraries for example: Entity Framework extended for logging, this article describes how to use Trackerenableddbcontext for operational log tracking.
1, first create project engineering, Trackerenableddbcontext only support 4.5 and above framework, details see: Https://www.nuget.org/packages/TrackerEnabledDbContext
2. Install the Entity Framework framework through NuGet.
3. Install the Trackerenableddbcontext framework through NuGet.
4, Add Mydbcontext class
5, configuring the database connection string
6, create the entity class, and note the use of the log trace flag.
7, modify the Mydbcontext, for the current operator configuration, for log tracking records.
8, run Enable-migrations-force.
9. Run add-migration to add a database migration
10, run Update-database for database creation.
11, view the database, in addition to the student table thought, also automatically added Auditlog, Auditlogdetail and logmetadata three tables. Auditlog and Auditlogdetail are used to store log information.
12, we are now student the operation of the additional pruning.
13, perform database validation insert operation.
14, perform database validation update operation.
15, perform a database validation delete operation.
Entity Framework entities frameworks use Trackerenableddbcontext for operational log tracking