Entity Framework entities frameworks use Trackerenableddbcontext for operational log tracking

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.