A lightweight library to automatically track entity changes (audit logs) in EF Core 9.0 with zero configuration.
- ✅ Automatic audit fields:
CreatedAt,CreatedBy,UpdatedAt,UpdatedBy - ✅ EF Core 9.0 optimized
- ✅ Supports custom user tracking via
ICurrentUserService - ✅ Minimal boilerplate (just inherit
AuditableEntity)
dotnet add package Softylines.EntityAuditpublic class CurrentUserService : ICurrentUserService
{
private readonly IHttpContextAccessor _httpContextAccessor;
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public string GetCurrentUser()
{
return _httpContextAccessor.HttpContext?.User?.Identity?.Name ?? "System";
}
}➡️ Register it in Program.cs:
builder.Services.AddScoped<ICurrentUserService, CurrentUserService>();
builder.Services.AddHttpContextAccessor();builder.Services.AddDbContext<AppDbContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("Postgres"))
.AddEntityAuditInterceptor();
});public class Product : AuditableEntity
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}✅ All audit fields are inherited from AuditableEntity and automatically handled.
dotnet ef migrations add Init
dotnet ef database updateEF Core will add audit fields like:
table.Column<string>(name: "CreatedBy", nullable: true),
table.Column<DateTime>(name: "CreatedAt", nullable: false),
table.Column<string>(name: "UpdatedBy", nullable: true),
table.Column<DateTime>(name: "UpdatedAt", nullable: true),✅ These fields are automatically filled in based on the user context!
EntityAudit gives you:
- 🔒 Transparent change tracking
- 👤 Full user-based auditing
- 🧼 Clean and minimal setup
Ready to audit your entities? Install it now and keep your data history clean and secure.