Skip to content

GrydAudit Module

GrydAudit is a comprehensive audit logging module for Gryd.IO applications. It provides automatic tracking of entity changes, user actions, and security events following the 5W1H principle (Who, What, When, Where, Why, How).

Features

  • Automatic Entity Tracking: Intercepts EF Core SaveChanges to capture all entity modifications
  • 5W1H Audit Principle: Captures complete context for each audit event
  • Builder Pattern: Fluent API for creating audit entries
  • CQRS Support: MediatR-based queries for retrieving audit logs
  • REST API: Ready-to-use endpoints for audit log access
  • Multi-tenant Ready: Full tenant isolation support
  • LGPD/GDPR Compliant: Sensitive data exclusion and compliance verification

Architecture

GrydAudit/
├── GrydAudit.Core/           # Domain entities and abstractions
├── GrydAudit.Application/    # CQRS handlers
├── GrydAudit.Infrastructure/ # EF Core implementation
├── GrydAudit.API/           # REST controllers
└── GrydAudit/               # Meta-package

Quick Start

1. Install the package

bash
dotnet add package GrydAudit

2. Configure services

csharp
services.AddGrydAudit(connectionString);

3. Mark entities as auditable

csharp
public class Product : IAuditableEntity
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    // ... other properties
}

See Getting Started for detailed setup instructions.

Packages

PackageDescription
GrydAudit.CoreDomain entities, abstractions, and DTOs
GrydAudit.ApplicationMediatR queries and handlers
GrydAudit.InfrastructureEF Core DbContext, interceptors, and repository
GrydAudit.APIREST API controllers
GrydAuditMeta-package including all above

Core Concepts

AuditLog Entity

The central entity that stores audit information:

  • Who: UserId, UserName, IpAddress, UserAgent
  • What: EntityType, EntityId, Action (Created/Updated/Deleted)
  • When: Timestamp (UTC)
  • Where: TenantId, ServiceName
  • Why: Reason (optional business justification)
  • How: PropertyChanges (old/new values)

Audit Actions

ActionDescription
CreatedEntity was inserted
UpdatedEntity was modified
DeletedEntity was removed
AccessedEntity was read (optional)

API Endpoints

MethodEndpointDescription
GET/api/auditlogs/{id}Get audit log by ID
GET/api/auditlogs/entity/{entityType}/{entityId}Get entity history
GET/api/auditlogs/user/{userId}Get user's audit logs
GET/api/auditlogs/searchSearch with filters

Released under the MIT License.