An audit trail (also called audit log) is one of the most effective ways to track user actions, which provides evidence of a sequence of activities that affect information, processes, and so on.
Using Entity Framework Core, we can easily audit changes overriding SaveChanges() method.
Let get it started
Define a context and entity classes that make up your model:
So, we should define an auditable context and AuditTrail model:
Execute EF migrations commands to create database:
dotnet ef migrations add InitialCreate --context BloggingContext
dotnet ef database update --context BloggingContext
Let’s test it
Add data on database:
INSERT INTO [Blogging].[dbo].[Blogs] (Url)
VALUES ('blog.victorleonardo.com');
Update a record on Blog data:
Voilà:
