Skip to content

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.

License

Notifications You must be signed in to change notification settings

msdkool/auditor

Repository files navigation

SimpleAuditor

Build StatusLicense: MIT NuGet Badge

Simple EntityFrameWorkCore Audit Log

About SimpleAuditor

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.

How to use

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.

GetUserName method

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.

Sample Code

The sample code can be found in the link below

https://github.com/msdkool/auditor/tree/master/Src/Auditor.Console

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages