Audit.NET.RavenDB 1.6.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Audit.NET.RavenDB --version 1.6.3                
NuGet\Install-Package Audit.NET.RavenDB -Version 1.6.3                
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="Audit.NET.RavenDB" Version="1.6.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Audit.NET.RavenDB --version 1.6.3                
#r "nuget: Audit.NET.RavenDB, 1.6.3"                
#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 Audit.NET.RavenDB as a Cake Addin
#addin nuget:?package=Audit.NET.RavenDB&version=1.6.3

// Install Audit.NET.RavenDB as a Cake Tool
#tool nuget:?package=Audit.NET.RavenDB&version=1.6.3                

Audit.NET.RavenDB

Quality Gate Status Build Status Vulnerabilities Coverage CodeQL

NuGet Status NuGet Count

Overview

RavenDB storage provider for Audit.NET

Setup

Set up the Audit.NET RavenDB provider during application startup with defaults storing object diffs

Audit.Core.Configuration.Setup()
  .UseRavenDB(configuration.GetSection("RavenSettings:Urls").Get<string[]>(),
    new X509Certificate2(Path.Combine(HttpContext.Current.Server.MapPath(""), configuration["RavenSettings:CertFilePath"]), configuration["RavenSettings:CertPassword"]),
    configuration["RavenSettings:DatabaseName"]);

Alternatively, set up the Audit.NET RavenDB provider during application startup storing full objects

Audit.Core.Configuration.Setup()
  .UseRavenDB(configuration.GetSection("RavenSettings:Urls").Get<string[]>(),
    new X509Certificate2(Path.Combine(HttpContext.Current.Server.MapPath(""), configuration["RavenSettings:CertFilePath"]), configuration["RavenSettings:CertPassword"]),
    configuration["RavenSettings:DatabaseName"], null, false);

Usage

Create an audit scope around the objects you are changing. Audit.NET takes a snapshot of the referenced object as it enters the scope, and compares it with the referenced object as it leaves the using block.

Audit creation of a new application, setting a custom field called Id to the app's Id after it's created

Application? app = null;
using (var audit = await AuditScope.CreateAsync("Application:Create", () => app))
{
    app = new Application
    {
        OwnerId = userId,
        Description = model.Description,
        Id = $"Applications/{Guid.NewGuid()}",
        Name = model.Name
    };
    await session.StoreAsync(app, ct);
    await session.SaveChangesAsync(ct);
    audit.SetCustomField(nameof(app.Id), app.Id);
}

Audit updating an application

using (var audit = await AuditScope.CreateAsync("Application:Update", () => app, new { app.Id }))
{
    app.Description = model.Description;
    app.Name = model.Name;
    app.Domain = model.Domain;
    app.DefaultEnvironment = model.DefaultEnvironment;

    await session.SaveChangesAsync(ct);
}

Known Bugs

No known bugs at this time. Please submit an issue if you encounter issues

Example audit records

Change property called Description on an object

{
    "Environment": {
        "UserName": "root",
        "MachineName": "7b7c96b853-ftlkw",
        "DomainName": "7b7c96b853-ftlkw",
        "CallingMethodName": "System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start()",
        "AssemblyName": "System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bdd7798e",
        "Culture": ""
    },
    "EventType": "Application:Update",
    "Target": {
        "Type": "Application",
        "Old": {
            "Description": "My Old Description"
        },
        "New": {
            "Description": "My New Description"
        }
    },
    "StartDate": "2022-03-30T13:51:45.3090112Z",
    "EndDate": "2022-03-30T13:51:45.3305599Z",
    "Duration": 22,
    "Id": "Applications/c9fa19a0-dafa-4f77-b751-3119475d0815",
    "UserId": "ApplicationUsers/1-A",
    "@metadata": {
        "@collection": "AuditEvents",
        "Raven-Clr-Type": "Audit.Core.AuditEvent, Audit.NET"
    }
}

Remove an object from a deeply nested array

{
    "Environment": {
        "UserName": "root",
        "MachineName": "7b7c96b855-rm8bl",
        "DomainName": "7b7c96b855-rm8bl",
        "CallingMethodName": "System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start()",
        "AssemblyName": "System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bdd7798e",
        "Culture": ""
    },
    "EventType": "Application:UpdateEnvironment",
    "Target": {
        "Type": "Application",
        "Old": {
            "Environments": {
                "Production": {
                    "Definitions": {
                        "Test": [
                            {
                                "Name": "AlwaysOn",
                                "Parameters": null
                            }
                        ]
                    }
                }
            }
        },
        "New": {
            "Environments": {
                "Production": {
                    "Definitions": {
                        "Test": []
                    }
                }
            }
        }
    },
    "StartDate": "2022-03-30T13:52:18.1276474Z",
    "EndDate": "2022-03-30T13:52:18.3096561Z",
    "Duration": 182,
    "Id": "Applications/c91119ad-aaaa-2277-b751-311aaaad0815",
    "UserId": "ApplicationUsers/1232-C",
    "@metadata": {
        "@collection": "AuditEvents",
        "Raven-Clr-Type": "Audit.Core.AuditEvent, Audit.NET"
    }
}
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 was computed.  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
27.1.1 73 10/28/2024
27.1.0 83 10/24/2024
27.0.3 132 9/25/2024
27.0.2 99 9/19/2024
27.0.1 198 9/4/2024
27.0.0 105 9/3/2024
26.0.1 246 8/22/2024
26.0.0 455 7/19/2024
25.0.7 212 7/4/2024
25.0.6 92 6/24/2024
25.0.5 115 6/18/2024
25.0.4 276 3/24/2024
25.0.3 165 3/13/2024
25.0.2 119 3/12/2024
25.0.1 114 2/28/2024
25.0.0 133 2/16/2024
24.0.1 122 2/12/2024
24.0.0 119 2/12/2024
23.0.0 271 12/14/2023
22.1.0 725 12/9/2023
22.0.2 658 12/1/2023
22.0.1 145 11/16/2023
22.0.0 109 11/14/2023
21.1.0 1,114 10/9/2023
21.0.4 185 9/15/2023
21.0.3 188 7/9/2023
21.0.2 156 7/6/2023
21.0.1 508 5/27/2023
21.0.0 397 4/15/2023
20.2.4 238 3/27/2023
20.2.3 245 3/17/2023
20.2.2 230 3/14/2023
20.2.1 837 3/11/2023
20.2.0 216 3/7/2023
20.1.6 259 2/23/2023
20.1.5 271 2/9/2023
20.1.4 496 1/28/2023
20.1.3 366 12/21/2022
20.1.2 312 12/14/2022
20.1.1 323 12/12/2022
20.1.0 341 12/4/2022
20.0.4 337 11/30/2022
20.0.3 667 10/28/2022
20.0.2 413 10/26/2022
20.0.1 454 10/21/2022
20.0.0 553 10/1/2022
19.4.1 552 9/10/2022
19.4.0 489 9/2/2022
19.3.0 487 8/23/2022
19.2.2 489 8/11/2022
19.2.1 498 8/6/2022
19.2.0 575 7/24/2022
19.1.4 1,043 5/23/2022
19.1.3 477 5/22/2022
19.1.2 493 5/18/2022
19.1.1 794 4/28/2022
19.1.0 1,012 4/10/2022
1.6.3 791 4/6/2022
1.6.2 2,458 3/30/2022
1.6.1 469 3/30/2022
1.6.0 470 3/30/2022
1.5.0 744 2/8/2022
1.4.1 732 2/8/2022
1.4.0 479 2/7/2022
1.3.2 509 2/1/2022
1.3.1 508 1/31/2022
1.3.0 478 1/31/2022
1.2.2 475 1/31/2022
1.2.1 461 1/31/2022
1.2.0 479 1/31/2022
1.1.0 477 1/31/2022
1.0.0 1,089 1/4/2021