Simple EntityFrameWorkCore Audit Log
SimpleAuditor is an audit library that enables you log changes made on your tables by simply putting the Audit attribute on the tables. The library makes it easy to log changes and also allows for override of the method of getting who effected the change.
To use SimpleAuditor
, add it by searching on Nuget manager or use the install command below
Install-Package SimpleAuditor
Run the SQL script to create the AuditTrail and AuditTrail tables in your Database
https://github.com/msdkool/auditor/tree/master/DbScript
Your DbContext should inherit from the AuditContext
public class ExampleDbContext : AuditContext
{
[Audit]
public DbSet<Person> Person { get; set; }
public ExampleDbContext(DbContextOptions<ExampleDbContext> options) : base(options)
{
}
public override string GetUserName()
{
return "TestUser";
}
}
In the example above the Person entity has been marked for Audit, SimpleAuditor will automatically detect this when a change is made and save whatever change is effected.
By default the library will attempt to access the IHttpContextAccessor
to fetch the identity of the person carrying out the action. The library allows you override that method in order to provide a custom GetUserName.
The sample code can be found in the link below
https://github.com/msdkool/auditor/tree/master/Src/Auditor.Console