Pandatech.AuditTrail 2.0.0

Suggested Alternatives

Pandatech.EFCore.Audit

Additional Details

We have newer version of nuget

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

// Install Pandatech.AuditTrail as a Cake Tool
#tool nuget:?package=Pandatech.AuditTrail&version=2.0.0                

1. Pandatech.AuditTrail

Pandatech.AuditTrail is a tool meticulously crafted to gather vital entity data from the change tracker post DbContext SaveChanges operation.

1.1 Features

Audits necessary entities for logging or preserving modified property data. Offers a convenient fluent configuration to specify tracked entities with ease.

1.2 Getting Started

Install the package via NuGet Package Manager or use the following command:

Install-Package Pandatech.AuditTrail

1.3 Usage

  • Implement IAuditTrailConsumer interface.
  • Add AddAuditTrail services by providing IAuditTrailConsumer implementation.
  • Create a rules derived from EntityRule.

1.3.1. Implement IAuditTrailConsumer Example:

Implement the IAuditTrailConsumer interface. To be able to retrive modified entities data after save operation.

public class AuditTrailConsumer<TPermission>() : IAuditTrailConsumer<TPermission>
{
   public async Task ConsumeAsync(IEnumerable<AuditTrailDataBeforeSave<TPermission>> auditData, 
        DbContextEventData? eventData, 
        CancellationToken cancellationToken = default)
   {
        // Handle tracked entites here.
   }
}

1.3.2. Add Services Example:

builder.Services.AddAuditTrail<PermissionType?, AuditTrailConsumer<PermissionType?>>(typeof(Registration).Assembly);

services.AddDbContextPool<SomeDbContext>((sp, options) =>
{
   options.UseAuditTrail<PermissionType?>(sp);
});

1.3.3 Create rule example:

Create a rule derived from EntityRule.

public class UserRule : EntityRule<UserEntity, PermissionType?>
{
   public UserRule(ISomeService someService)
   {
      SetPermission(PermissionType.Users_Read);

      RuleFor(s => s.PasswordHash).Ignore();
      RuleFor(s => s.Status).ChangeName("UserStatus");
   }
}

1.3.4 Create Custom Rule Example:

You can create your own rules and modify properties as needed.

public class ChangeNamePropertyRule<TEntity, TProperty> : PropertyRule<TEntity, TProperty>
{
    private readonly string _changeName;

    public override NameValue ExecuteRule(string name, object value)
    {
        return new NameValue(_changeName, value);
    }

    public ChangeNamePropertyRule(string name)
    {
        _changeName = name;
    }
}

public static class RuleExtensions
{
    public static IRuleBulder<T, TPermission, TProperty?> ChangeName<T, TPermission, TProperty>(this IRuleBulder<T, TPermission, TProperty> ruleBuilder, string name)
        where T : class
    {
        var rule = new ChangeNamePropertyRule<T, TProperty?>(name);
        return ruleBuilder.SetRule(rule!)!;
    }
}

1.4 Limitations

  • In case of composite keys only first key will be selected as entityId.

1.5. Contributing

Contributions are welcome! Please submit a pull request or open an issue to propose changes or report bugs.

1.6 License

Pandatech.AuditTrail is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
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

.Net 9 upgrade