Skip to content
gabisoniaPublic

About

Audit trail library for .net

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

Kvali - კვალი

Kvali (Georgian: კვალი) is a lightweight and flexible .NET Core library for implementing audit trails in your applications. It helps you track changes, log actions, and maintain a detailed history of operations for auditing and debugging purposes.

Requires .NET 10 (net10.0) and Entity Framework Core 10.

Features

  • Seamless integration with .NET Core applications.
  • Tracks and logs create, update, and delete operations.
  • Stores comprehensive audit data, including datetime, user actions, and object changes.
  • Configurable and extensible for custom audit requirements.
  • Lightweight and performance-oriented.

Usage

1. Register the interceptor on your DbContext

To enable auditing, keep your context as a normal DbContext, add a DbSet<AuditEntry>, and register the interceptor through DbContextOptionsBuilder:

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options)
        : base(options) { }

    public DbSet<Entities> Products { get; set; }
    public DbSet<User> Users { get; set; }
    public DbSet<AuditEntry> AuditLogs { get; set; }
}
services.AddDbContext<AppDbContext>(options =>
    options
        .UseSqlServer(connectionString)
        .UseKvaliAuditTrail());

You can also register the interceptor manually with options.AddInterceptors(new AuditSaveChangesInterceptor()).

2. Annotate your models for auditing

[Auditable]
public class Entities
{
    public int Id { get; set; }
    public string Name { get; set; }

    // This property will be ignored during auditing.
    [IgnoreAudit]
    public decimal Price { get; set; }
}

Or

public class Entities : IAuditable
{
    public int Id { get; set; }
    public string Name { get; set; }

    // This property will be ignored during auditing.
    [IgnoreAudit]
    public decimal Price { get; set; }
}

3. Action-Specific Auditing

// Only audits on create actions.
[AuditAction(AuditActionType.Create)]
public class User : IAuditable
{
    public int Id { get; set; }
    public string Name { get; set; }
}

4. Add and Apply Migrations

Before using Kvali, ensure you generate and apply the necessary migrations to your database. Follow these steps:

  1. Generate the Migration:

    Run the following command in the Package Manager Console or terminal:

    dotnet ef migrations add InitialAuditMigration
  2. Apply the Migration::

    Run the following command to update the database with the migration:

    dotnet ef database update

License

Kvali is fully free to use, modify, and distribute for any purpose, personal or commercial.

No attribution is required, but contributions and feedback are always welcome!

About

Audit trail library for .net

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages