NLBAudit.Store.EfCore 2.0.0

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

NLBAudit - Comprehensive and Extensible Auditing Library

License

Overview

NLBAudit is a comprehensive and extensible auditing library for .NET applications. It provides functionalities to log and track method executions, including details such as execution time, duration, input parameters, return values, and exceptions. The library is designed to be easily integrated with Entity Framework Core and ASP.NET Core applications.

Features

  • Auditing of method executions
  • Logging of user information, IP address, and browser details
  • Integration with Entity Framework Core
  • Customizable audit log storage
  • Exception tracking

Getting Started

Prerequisites

  • .NET 8.0

Installation

To install NLBAudit, add the following NuGet package to your project:

dotnet add package NLBAudit.Core

It is framework independent package and will write audit records to logs and will use test session and test client. It is useful for testing purposes

If you want to integrate NLBAudit to ASP.NET Core API project you need to install to additional packages

dotnet add package NLBAudit.AspNetCore
dotnet add package NLBAudit.Store.EfCore

Entity Framework Core Configuration

  1. Define your DbContext:

    public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options), IAuditedContext<int>
    {
        public DbSet<AuditLogEntity<int>> AuditLogs { get; set; }
    
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ConfigureEfCoreAuditing<int>();
            modelBuilder.Entity<AuditLogEntity<int>>().ToTable("AuditLogs");
        }
    }
    
  2. Configure your DbContext in Program.cs:

    builder.Services.AddDbContext<MyDbContext>(options =>
    {
        options.UseSqlServer(builder.Configuration.GetConnectionString("MyConnectionString"));
    });
    
    builder.Services.ConfigureAuditingEfCoreStore<int, MyDbContext>();
    

ASP.NET Core Integration

  1. Register the auditing services in Program.cs:

    builder.Services.ConfigureAspNetCoreAuditing<int>(config =>
    {
        config.IsEnabled = true;
        config.IsEnabledForAnonymousUsers = true;
        config.SaveReturnValues = true;
    });
    
  2. Use the auditing filter for Web APIs:

    builder.Services.AddControllers(options =>
    {
        options.AddAuditingFilter<int>();
    });
    
  3. Use the endpoint filter for Minimal APIs:

     app.MapGet("/weatherforecast", () =>
            {
                var forecast = Enumerable.Range(1, 5).Select(index =>
                                             new WeatherForecast
                                             (
                                                 DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                                                 Random.Shared.Next(-20, 55),
                                                 summaries[Random.Shared.Next(summaries.Length)]
                                             ))
                                         .ToArray();
                return forecast;
            })
            .AddEndpointFilter<MinimalApiEndpointAuditFilter<int>>()
    

Usage

This is all you need 😃

Customization

You can customize the audit logging by extending the AuditInfo class or implementing your own storage mechanism by extending IAuditingStore.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT LICENSE. You are free to use it in both commercial and open-source software.

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 was computed.  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
2.0.0 148 2/12/2025
1.0.0 128 2/11/2025