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
<PackageReference Include="NLBAudit.Store.EfCore" Version="2.0.0" />
<PackageVersion Include="NLBAudit.Store.EfCore" Version="2.0.0" />
<PackageReference Include="NLBAudit.Store.EfCore" />
paket add NLBAudit.Store.EfCore --version 2.0.0
#r "nuget: NLBAudit.Store.EfCore, 2.0.0"
#:package NLBAudit.Store.EfCore@2.0.0
#addin nuget:?package=NLBAudit.Store.EfCore&version=2.0.0
#tool nuget:?package=NLBAudit.Store.EfCore&version=2.0.0
NLBAudit - Comprehensive and Extensible Auditing Library
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
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"); } }
Configure your
DbContext
inProgram.cs
:builder.Services.AddDbContext<MyDbContext>(options => { options.UseSqlServer(builder.Configuration.GetConnectionString("MyConnectionString")); }); builder.Services.ConfigureAuditingEfCoreStore<int, MyDbContext>();
ASP.NET Core Integration
Register the auditing services in
Program.cs
:builder.Services.ConfigureAspNetCoreAuditing<int>(config => { config.IsEnabled = true; config.IsEnabledForAnonymousUsers = true; config.SaveReturnValues = true; });
Use the auditing filter for Web APIs:
builder.Services.AddControllers(options => { options.AddAuditingFilter<int>(); });
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 | Versions 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.12)
- NLBAudit.Core (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.