AuditLog.Abstractions 0.4.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package AuditLog.Abstractions --version 0.4.5
                    
NuGet\Install-Package AuditLog.Abstractions -Version 0.4.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AuditLog.Abstractions" Version="0.4.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuditLog.Abstractions" Version="0.4.5" />
                    
Directory.Packages.props
<PackageReference Include="AuditLog.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AuditLog.Abstractions --version 0.4.5
                    
#r "nuget: AuditLog.Abstractions, 0.4.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AuditLog.Abstractions@0.4.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AuditLog.Abstractions&version=0.4.5
                    
Install as a Cake Addin
#tool nuget:?package=AuditLog.Abstractions&version=0.4.5
                    
Install as a Cake Tool

AuditLog

Publish to NuGet

Biblioteca de auditoria automática para EF Core com Source Generators Roslyn.

Pacotes

Pacote Descrição
AuditLog.Abstractions Contratos: AuditConfigurator<T>, IAuditDescriptor, builders
AuditLog.EntityFrameworkCore Integração EF Core: AuditSaveInterceptor, extensions
AuditLog.Generator Source generator — gera *AuditLog, maps, descriptors
AuditLog.EntityFrameworkCore.SoftDelete Runtime: interfaces, interceptor, query filters para soft delete
AuditLog.Generator.SoftDelete Source generator — gera handlers tipados de cascade/restrict/set-null

AuditLog — Auditoria de Entidades

1. Defina um configurador

[GenerateAuditLog]
public sealed class PacienteAuditConfigurator : AuditConfigurator<Paciente>
{
    public PacienteAuditConfigurator()
    {
        For(x => x.Id).Key();
        For(x => x.Nome).HasMaxLength(200).IsRequired();
        For(x => x.Cpf).Sensitive().HasMaxLength(11);
        For(x => x.DataAtualizacao).Ignore();
    }
}

2. Adicione o interceptor no DbContext

public class AppDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.AddInterceptors(new AuditSaveInterceptor());
    }
}

3. O generator produz automaticamente

  • PacienteAuditLog — tabela de auditoria com snapshot dos dados
  • PacienteAuditLogDescriptor — mapeia Paciente → PacienteAuditLog
  • PacienteAuditLogEntityMap — EF Core configuration (column types, max length)
  • ServiceCollectionExtensions.AddGeneratedAuditLogs() — DI registration

SoftDelete — Exclusão Lógica

Dois pacotes complementares:

Package Função
AuditLog.EntityFrameworkCore.SoftDelete Runtime: interceptor, interfaces, query filters
AuditLog.Generator.SoftDelete Source generator (opcional): gera handlers com tipagem forte

Instalação

<ItemGroup>
  <PackageReference Include="AuditLog.EntityFrameworkCore.SoftDelete" Version="1.0.0" />
  <PackageReference Include="AuditLog.Generator.SoftDelete" Version="1.0.0" />
</ItemGroup>

1. Implemente ISoftDeleteEntity nas entidades

public class Paciente : ISoftDeleteEntity
{
    public Guid Id { get; set; }
    public string Nome { get; set; }

    // Obrigatório para soft delete
    public bool IsDeleted { get; set; }
    public DateTime? DeletedAt { get; set; }

    // Relacionamentos (Fluent API configurada no DbContext)
    public List<Notificacao> Notificacoes { get; set; } = [];
}

2. Marque o DbContext com [GenerateSoftDelete]

using AuditLog.EntityFrameworkCore.SoftDelete;

[GenerateSoftDelete]
public class AppDbContext : DbContext
{
    public DbSet<Paciente> Pacientes { get; set; }
    public DbSet<Notificacao> Notificacoes { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Paciente>(e =>
        {
            e.HasMany(x => x.Notificacoes)
                .WithOne(x => x.Paciente)
                .HasForeignKey(x => x.PacienteId)
                .OnDelete(DeleteBehavior.Cascade);
        });

        modelBuilder.ApplySoftDeleteQueryFilter();
    }
}

3. Registre na DI

// Com o source generator (handlers tipados)
var registry = new SoftDeleteHandlerRegistry();
registry.AddGeneratedSoftDeleteHandlers();
services.AddSoftDelete(registry);

// Ou sem o generator (fallback via reflection)
services.AddSoftDelete();

4. Use normalmente

db.Pacientes.Remove(paciente);
await db.SaveChangesAsync();
// → IsDeleted = true, DeletedAt = now
// → Cascade: Notificacoes também são marcadas como deletadas
// → Query filter global: db.Pacientes retorna apenas não-deletados

Comportamentos por FK

OnDelete() Efeito
Cascade Dependentes são soft-deletados recursivamente
Restrict Lança RestrictDeleteViolationException se houver dependentes
SetNull FK dos dependentes é setada como null

Convenções (quando OnDelete não é especificado)

Navigation Comportamento
Collection (List<T>) Cascade
Reference (T) Restrict
FK nullable (Guid?) SetNull

Consultas

// Query filter automático — só não-deletados
db.Pacientes.ToList();

// Incluir deletados
db.Pacientes.IgnoreQueryFilters().ToList();

Suporte a herança indireta de IEntityTypeConfiguration<T>

O gerador detecta entity maps que implementam IEntityTypeConfiguration<T> através de toda a cadeia de herança, incluindo casos como AuditEntityMap<T>IContextEntityMap<T>IEntityTypeConfiguration<T>. Isso funciona tanto com ApplyConfiguration(new ConcreteEntityMap()) quanto com ApplyConfigurationsFromAssembly().

Descoberta de entidades sem DbSet<T>

O gerador descobre entidades mesmo quando o DbContext não possui propriedades DbSet<T>, desde que as entidades sejam registradas via modelBuilder.Entity<T>() no OnModelCreating ou via ApplyConfiguration/ApplyConfigurationsFromAssembly com entity maps que implementam IEntityTypeConfiguration<T>.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AuditLog.Abstractions:

Package Downloads
AuditLog.EntityFrameworkCore

EF Core integration for AuditLog — AuditSaveInterceptor, service collection extensions, and model builder hooks.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.7 34 7/23/2026
0.4.6 42 7/23/2026
0.4.5 61 7/23/2026
0.4.4 56 7/22/2026
0.4.3 46 7/22/2026
0.4.2 36 7/22/2026
0.4.1 38 7/22/2026
0.4.0 42 7/22/2026
0.3.3 90 7/20/2026
0.3.1 80 7/20/2026
0.3.0 94 7/20/2026
0.2.0 116 6/30/2026
0.1.0 108 6/30/2026