audit-trail

Automatically populate audit fields on EF Core entity saves.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill audit-trail-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: audit-trail
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/data/audit-trail
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill audit-trail-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Ensures consistent and reliable population of audit metadata (CreatedAt, UpdatedAt, CreatedBy, UpdatedBy) across entity saves so developers don't have to set audit fields manually in handlers or services.

Core Features & Use Cases

  • IAuditable Interface: Define a minimal contract for entities that require audit fields.
  • EF Core SaveChangesInterceptor: Centralized logic to set timestamps and user identifiers on Added and Modified entity states.
  • Soft Delete Support: Convert hard deletes into soft deletes via an ISoftDeletable pattern and apply global query filters.
  • DI Registration & Configuration: Register interceptor and DbContext wiring to ensure automatic behavior at runtime.
  • Detection & Adoption: Simple grep patterns and migration steps to add auditing to an existing codebase.

Quick Start

Add the IAuditable interface to your domain entities and register the AuditableEntityInterceptor so EF Core automatically sets CreatedAt, UpdatedAt, CreatedBy, and UpdatedBy on save.

Frequently Asked Questions about audit-trail

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automatically populate audit fields in EF Core on entity saves?

To automatically populate audit fields in EF Core, you can implement an IAuditable interface on your entities and use a SaveChangesInterceptor. This interceptor hooks into DbContext saves to inject timestamps and user identifiers for CreatedAt and UpdatedAt without manual code in services.

What is the best way to implement soft delete with EF Core global query filters?

Implementing soft delete with EF Core involves using an ISoftDeletable pattern for your entities and applying global query filters in your DbContext. This approach automatically converts hard deletes into soft deletes, hiding removed records from query results by default.

How do I set up a SaveChangesInterceptor for CreatedBy and UpdatedBy in .NET?

Setting up a SaveChangesInterceptor for CreatedBy and UpdatedBy requires wiring the interceptor into your DbContext dependency injection registration. During entity Added and Modified states, it automatically injects the current user identifiers and timestamps into the auditable fields.

Do I need to manually set CreatedAt and UpdatedAt in my domain services when using EF Core?

You do not need to manually set CreatedAt and UpdatedAt in domain services if you use a centralized EF Core SaveChangesInterceptor. It automatically handles the population of these audit metadata fields during entity saves, ensuring consistent tracking.

Can I add automatic auditing to an existing .NET project without rewriting my domain models?

You can add automatic auditing to an existing .NET project by using simple grep patterns to detect entity classes and applying migration steps. You simply add the IAuditable interface to your domain objects and register the AuditableEntityInterceptor.

Why are my EF Core soft delete query filters not applying to deleted records?

If your EF Core soft delete query filters are not applying, ensure your entities implement the ISoftDeletable pattern and your DbContext has global query filters correctly configured. The SaveChangesInterceptor must also be properly wired to convert hard deletes into soft deletes.