Aiirh.Audit 2.0.6

dotnet add package Aiirh.Audit --version 2.0.6
NuGet\Install-Package Aiirh.Audit -Version 2.0.6
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="Aiirh.Audit" Version="2.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aiirh.Audit --version 2.0.6
#r "nuget: Aiirh.Audit, 2.0.6"
#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.
// Install Aiirh.Audit as a Cake Addin
#addin nuget:?package=Aiirh.Audit&version=2.0.6

// Install Aiirh.Audit as a Cake Tool
#tool nuget:?package=Aiirh.Audit&version=2.0.6

Aiirh.Audit

This library provides functionality of tracking changes between two objects of the same data class, based on comparing so-called Revisions, that have to be created and stored every time when trackable data change is done

Installing package

Install package using NuGet Package Manager

Install-Package Aiirh.Audit

or using .NET CLI

dotnet add package Aiirh.Audit

How to use

Prepare your data class

To make class properties to track changes, mark them with Auditable attribute. Only properties with this attribute are trackable.

using Aiirh.Audit;

public class Product
{
    [Auditable(DisplayName = "Product price", PropertyName = "Price")]
    public decimal Price { get; set; }

    public string Name { get; set; } // Changes of this property value will not be tracked
}

DisplayName parameter is used to specify, what label to show (e.g. in UI) as a name/label of changed property.

PropertyName parameter is an override for the real property name. It can be useful in situations, when property in the class is renamed, but you want to support previous revisions that have been created before renaming. Comparing values is done either by PropertyName attribute if provided, or by ther real property name how it is named in the class.

Create revisions

Every time when change is done (e.g. Price is updated), you need to create a Revision, providing a date when revision was created, author of the change, and a custom comment

// Find your product and update the price
var product = await myProductRepository.FindMyProduct();
product.Price = 123m;

// Create revision for updated product
var revision = product.CreateRevision(DateTime.UtcNow, "John Smith", "Price has been updated manually from admin page");

Now you need to store this revision in a way to be able to find revisions for exact this product later.

Note! Since at least two revisions are needed to detect a change, there is a need to create initial revision on object creation. Otherwise the first change will not be shown.

Build audit log

Read all revision related to the same object

// Find the product
var product = await myProductRepository.FindMyProduct();

// Read related revisions
var revisions = await myRevisionRepository.GetAllRevisionsByProductId(product.Id);

// Build audit log
var auditLogs = revisions.ToAuditLog();

auditLogs is a collection IEnumerable<IAuditLog>. One IAuditLog represents one change between two revisions. IAuditLog contains a collection IEnumerable<IAuditLogEntry> Changes. One IAuditLogEntry represents one change of one property marked with Auditable attribute.

Result

Use auditLogs data to display the product change history in any manner you need.

Note! This package is not supposed to handle big volums of data, so the method .ToAuditLog() may come across poor performance working with hundreds of revisions, so it has an optional paratemeter int? depth = null to limit output and returning only depth latest changes. Also you can limit an amount of provided revisions on your side.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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.6 76 5/23/2024
2.0.5 63 5/20/2024
2.0.4 76 5/19/2024
2.0.3 115 4/9/2024
2.0.2 88 4/9/2024
2.0.1 112 2/27/2024
2.0.0 80 2/26/2024
1.2.0 82 2/26/2024
1.1.1 103 2/16/2024
1.1.0 99 2/14/2024
1.0.7 105 1/31/2024
1.0.6 228 11/6/2023
1.0.5 133 9/22/2023
1.0.4 117 9/19/2023
1.0.3 124 9/13/2023
1.0.2 134 9/11/2023
1.0.1 124 9/11/2023
1.0.0 127 9/8/2023