Linger.Audit 0.7.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Linger.Audit --version 0.7.2
                    
NuGet\Install-Package Linger.Audit -Version 0.7.2
                    
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="Linger.Audit" Version="0.7.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.Audit" Version="0.7.2" />
                    
Directory.Packages.props
<PackageReference Include="Linger.Audit" />
                    
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 Linger.Audit --version 0.7.2
                    
#r "nuget: Linger.Audit, 0.7.2"
                    
#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 Linger.Audit@0.7.2
                    
#: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=Linger.Audit&version=0.7.2
                    
Install as a Cake Addin
#tool nuget:?package=Linger.Audit&version=0.7.2
                    
Install as a Cake Tool

Linger.Audit

πŸ“ View this document in: English | δΈ­ζ–‡

NuGet Downloads License

A lightweight .NET auditing library that provides base classes and interfaces for entity auditing.

✨ Features

  • Multi-target framework support (.NET 9.0/.NET 8.0/.NET 6.0/NetStandard 2.0)
  • Full audit trail tracking (creation, modification, deletion)
  • Generic entity support with type-safe IDs
  • Soft delete capability
  • Built-in audit timestamps and user tracking
  • Nullable reference types enabled
  • MIT licensed

πŸ“¦ Installation

From Visual Studio

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages....
  4. Click on the Browse tab and search for "Linger.Audit".
  5. Click on the Linger.Audit package, select the appropriate version and click Install.

Package Manager Console

PM> Install-Package Linger.Audit

.NET CLI Console

> dotnet add package Linger.Audit

πŸš€ Quick Start

Basic Setup

// 1. Implement audit user provider 
public class CurrentUserProvider : IAuditUserProvider 
{ 
    public string? UserName => "current-user"; 
    public string GetUser() => UserName ?? "anonymous"; 
}

// 2. Create auditable entity 
public class Product : FullAuditEntity 
{ 
    public string Name { get; set; } = default!; 
    public decimal Price { get; set; }
}

// The entity will track: 
// - Creation time and creator 
// - Last modification time and modifier
// - Deletion time and deleter 
// - Soft delete status

Using with Dependency Injection

// Register in your DI container
services.AddSingleton<IAuditUserProvider, CurrentUserProvider>();

// Usage with Entity Framework Core
public class ApplicationDbContext : DbContext
{
    private readonly IAuditUserProvider _auditUserProvider;
    
    public ApplicationDbContext(
        DbContextOptions<ApplicationDbContext> options,
        IAuditUserProvider auditUserProvider) : base(options)
    {
        _auditUserProvider = auditUserProvider;
    }
    
    public override int SaveChanges()
    {
        UpdateAuditFields();
        return base.SaveChanges();
    }
    
    private void UpdateAuditFields()
    {
        var entries = ChangeTracker.Entries().Where(e => 
            e.State == EntityState.Added || 
            e.State == EntityState.Modified ||
            e.State == EntityState.Deleted);
            
        foreach (var entry in entries)
        {
            if (entry.Entity is IAuditableEntity auditableEntity)
            {
                if (entry.State == EntityState.Added)
                {
                    auditableEntity.CreationTime = DateTime.UtcNow;
                    auditableEntity.CreatorUserId = _auditUserProvider.GetUser();
                }
                else if (entry.State == EntityState.Modified)
                {
                    auditableEntity.LastModificationTime = DateTime.UtcNow;
                    auditableEntity.LastModifierUserId = _auditUserProvider.GetUser();
                }
            }
            
            if (entry.State == EntityState.Deleted && entry.Entity is ISoftDelete softDelete)
            {
                entry.State = EntityState.Modified;
                softDelete.IsDeleted = true;
                softDelete.DeletionTime = DateTime.UtcNow;
                softDelete.DeleterUserId = _auditUserProvider.GetUser();
            }
        }
    }
}

πŸ—οΈ Architecture

Linger.Audit provides the following key components:

  • IAuditUserProvider - Interface for getting current user
  • FullAuditEntity<T> - Base class for entities with full audit trail and generic ID type
  • FullAuditEntity - Base class for entities with full audit trail using string ID type
  • AuditableEntity<T> - Base class with creation/modification audit and generic ID type
  • AuditableEntity - Base class with creation/modification audit using string ID type
  • ISoftDelete - Interface for soft delete support

❓ Frequently Asked Questions

How to use custom ID types?

// Using Guid as ID type
public class Customer : FullAuditEntity<Guid> 
{
    public string Name { get; set; } = default!;
    public string Email { get; set; } = default!;
}

// Using int as ID type
public class Order : FullAuditEntity<int>
{
    public DateTime OrderDate { get; set; }
    public decimal TotalAmount { get; set; }
}

How to use only partial auditing features?

// Only need creation and modification auditing
public class SimpleProduct : AuditableEntity
{
    public string Name { get; set; } = default!;
}

// Only need soft delete functionality
public class Document : Entity, ISoftDelete
{
    public string Title { get; set; } = default!;
    public bool IsDeleted { get; set; }
    public DateTime? DeletionTime { get; set; }
    public string? DeleterUserId { get; set; }
}

🀝 Contributing

Contributions are welcome! If you have feature requests, bug reports, or pull requests, please feel free to submit them on our GitHub repository.

πŸ“ License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Linger.Audit:

Package Downloads
Linger.EFCore.Audit

An Entity Framework Core audit trail library for automatically tracking data changes. Captures entity creation, modification, and deletion events with old and new values. Provides configurable audit logging with support for user tracking and timestamping.

Linger.Audit.EFCore

C# Helper Library

Linger.Repository.Contracts

C# Helper Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.0-preview 56 9/12/2025
0.8.5-preview 151 8/31/2025
0.8.4-preview 267 8/25/2025
0.8.3-preview 130 8/20/2025
0.8.2-preview 168 8/4/2025
0.8.1-preview 96 7/30/2025
0.8.0-preview 534 7/22/2025
0.7.2 163 6/3/2025
0.7.1 160 5/21/2025
0.7.0 154 5/19/2025
0.6.0-alpha 166 4/28/2025
0.5.0-alpha 162 4/10/2025
0.4.0-alpha 155 4/1/2025
0.3.3-alpha 166 3/19/2025
0.3.2-alpha 160 3/17/2025
0.3.1-alpha 145 3/16/2025
0.3.0-alpha 214 3/6/2025
0.2.0-alpha 103 2/9/2025
0.1.2-alpha 104 12/17/2024
0.1.1-alpha 84 12/17/2024
0.1.0-alpha 100 12/6/2024
0.0.3-alpha 101 11/27/2024
0.0.2-alpha 94 10/3/2024
0.0.1-alpha 112 9/28/2024