TL.AuditLogger 0.5.0

dotnet add package TL.AuditLogger --version 0.5.0
                    
NuGet\Install-Package TL.AuditLogger -Version 0.5.0
                    
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="TL.AuditLogger" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TL.AuditLogger" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="TL.AuditLogger" />
                    
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 TL.AuditLogger --version 0.5.0
                    
#r "nuget: TL.AuditLogger, 0.5.0"
                    
#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 TL.AuditLogger@0.5.0
                    
#: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=TL.AuditLogger&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=TL.AuditLogger&version=0.5.0
                    
Install as a Cake Tool

🛡️ TL.AuditLogger

NuGet .NET License: MIT

Structured audit logging utility for .NET: automatic JSON property diff calculation, pluggable storage backends, and zero-leak event dispatching.
Biblioteca de auditoria estruturada para .NET: cálculo automático de diff diferencial JSON por propriedade, provedores plugáveis de armazenamento e despacho sem vazamento de memória.

O TL.AuditLogger fornece uma infraestrutura robusta e desacoplada para rastrear operações de alteração de estado (CRUD) em aplicações .NET. Ele captura o estado anterior e posterior das entidades, computa automaticamente o diferencial estruturado em JSON e despacha os registros para destinos de armazenamento configuráveis.


📦 Instalação

Adicione o pacote ao seu projeto através do .NET CLI:

dotnet add package TL.AuditLogger

🚀 Funcionalidades Principais

Categoria Componentes & Métodos Descrição
Operações de Auditoria LogCreate(), LogUpdate(), LogDelete() (sync e async) Registro de mutações retornando Guid com identificação de usuário, entidade e contexto.
Cálculo de Diff Estruturado AuditLogEntry, JsonDiffCalculator Geração automática de histórico diferencial JSON estruturado (Old, New, Diff).
Mascaramento de Dados Sensíveis [SensitiveData], heurísticas Mascaramento automático (***) de senhas, CPFs, tokens e dados confidenciais (LGPD/GDPR).
Higienização CRLF CrlfSanitizer Neutralização rigorosa de \r e \n em campos textuais contra Log Injection.
Contexto Distribuído AuditCorrelationContext Captura automática de CorrelationId (W3C/OpenTelemetry) e TenantId multi-inquilino.
Emissão & Sinks ILogger<AuditLogger>, MemoryCache Emissão via ILogger, desacoplada de dependências de terceiros, com adaptadores legados.
Injeção de Dependência AddAuditLogger(IConfiguration) Configuração fluente no container nativo do .NET com validação de opções.

💡 Exemplos de Uso

1. Entidade com Proteção de Dados Sensíveis

using AuditLogger;

public class Usuario
{
    public int Id { get; set; }
    public string Nome { get; set; } = string.Empty;

    [SensitiveData]
    public string SenhaHash { get; set; } = string.Empty;

    public string Cpf { get; set; } = string.Empty; // Mascarado automaticamente por convenção heurística
}

2. Registro em Injeção de Dependência

using AuditLogger.DependencyInjection;

// No Program.cs
builder.Services.AddAuditLogger(builder.Configuration);

3. Configuração no appsettings.json

{
  "AuditLoggerSettings": {
    "StorageType": "Logger",
    "EnableHeuristicMasking": true,
    "DefaultMask": "***"
  }
}

4. Registro Estruturado com Cálculo Automático de Diff

using AuditLogger.Interfaces;

public class UsuarioService
{
    private readonly IAuditLogger _auditLogger;

    public UsuarioService(IAuditLogger auditLogger)
    {
        _auditLogger = auditLogger;
    }

    public async Task AtualizarUsuarioAsync(Usuario original, Usuario modificado, string usuarioId)
    {
        modificado.Nome = "Novo Nome";
        modificado.SenhaHash = "novo_hash_secreto";

        // SenhaHash e CPF são automaticamente mascarados como "***" no payload JSON
        Guid logId = await _auditLogger.LogUpdateAsync(original, modificado, usuarioId);
    }
}

🏛️ Decisões Arquiteturais e Segurança

Para detalhes sobre governança, ciclo de vida de instâncias e estratégias de isolamento de log:


📄 Licença

Distribuído sob a licença MIT.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 107 9/27/2026
0.4.0 107 9/23/2026
0.3.0 112 9/18/2026
0.2.0 121 9/12/2026
0.1.0 123 9/7/2026