AuditTracker 1.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AuditTracker --version 1.0.1
                    
NuGet\Install-Package AuditTracker -Version 1.0.1
                    
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="AuditTracker" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuditTracker" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AuditTracker" />
                    
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 AuditTracker --version 1.0.1
                    
#r "nuget: AuditTracker, 1.0.1"
                    
#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 AuditTracker@1.0.1
                    
#: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=AuditTracker&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AuditTracker&version=1.0.1
                    
Install as a Cake Tool

AuditTracker

AuditTracker is a flexible and extensible library for tracking and logging changes to entities in your application. It supports entity and API auditing, background processing, and fully customizable configuration.


🚀 Features

  • Entity Auditing: Automatically logs insert, update, and delete operations on entities.
  • API Auditing: Tracks incoming API requests and outgoing responses (optional).
  • Background Processing: Supports asynchronous processing of audit logs.
  • Customizable Writers: Implement IAuditLogWriter to control how and where audit logs are saved (e.g., database, file, etc.).
  • Extensible Options: Configure behavior using AuditLogTrackerOptions.

📦 Requirements

  • .NET Version: .NET 8
  • C# Version: 12.0

📥 Installation

Install the required NuGet packages:

dotnet add package Microsoft.Extensions.Logging
dotnet add package Microsoft.Extensions.Options

⚙️ Usage

  1. Configure Services

In your Startup.cs or Program.cs:

builder.Services.AddAuditLogTracker(options =>
{
	//Add options
});

//Add Provider do you want to use
builder.Services.AddSqlAuditLogWriter(options =>
{
	options.ConnectionString = builder.Configuration.GetConnectionString("SqlServer");
	options.CreateTablesIfNotExist = true;
});

//Add Middleware to track API
app.UseApiAuditLogging();
  1. Implement on DbContext

Override SaveChanges method in your DbContext to add handler to track changes

using AuditTracker.Extensions;

public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
	// Track changes before saving them
	this.EnableAuditTracking(
			_auditLogger,
			GetCurrentUserId,
			GetCurrentUsername);

	return await base.SaveChangesAsync(cancellationToken);
}

🛠 Configuration Options

Customize behavior via AuditLogTrackerOptions:

Option Description Default
EnableEntityAuditing Enables auditing for entity operations. false
EnableApiAuditing Enables auditing for API requests/responses. false
UseBackgroundProcessing Enables background task processing for audit logs. false
ApplicationName Sets the application name for contextual audit information. null
SanitizeRequestResponse Removes sensitive data from request/response logs. false
CaptureRequestBody Logs the body of incoming requests. false
CaptureResponseBody Logs the body of outgoing responses. false
CaptureRequestHeaders Logs headers from incoming requests. false
CaptureResponseHeaders Logs headers from outgoing responses. false
IncludedPaths Filters API routes to include in auditing. null
ExcludedPaths Filters API routes to exclude from auditing. null

Example:

services.Configure<AuditLogTrackerOptions>(options =>
{
    options.EnableEntityAuditing = true;
    options.EnableApiAuditing = false;
    options.UseBackgroundProcessing = true;
    options.ApplicationName = "MyApplication";
    options.SanitizeRequestResponse = true;
    options.CaptureRequestBody = true;
    options.CaptureResponseBody = true;
    options.CaptureRequestHeaders = true;
    options.CaptureResponseHeaders = true;
    options.IncludedPaths = new[] { "/api/v1/*" };
    options.ExcludedPaths = new[] { "/api/v1/health" };
});

🧩 Extensibility

Custom Entity ID Resolution

The DefaultAuditLogger uses reflection to resolve entity IDs. You can override this by customizing the GetEntityId method.

Ignoring Properties

Override the IsIgnoredProperty method to exclude specific properties from auditing.

🪵 Error Logging

The library uses ILogger to log internal errors. Ensure your application has a configured logging provider.

🤝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the library.

Happy auditing! 🎉

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