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 67 10/28/2024
27.1.0 77 10/24/2024
27.0.3 109 9/25/2024
27.0.2 95 9/19/2024
27.0.1 189 9/4/2024
27.0.0 102 9/3/2024
26.0.1 218 8/22/2024
26.0.0 452 7/19/2024
25.0.7 209 7/4/2024
25.0.6 88 6/24/2024
25.0.5 111 6/18/2024
25.0.4 271 3/24/2024
25.0.3 160 3/13/2024
25.0.2 114 3/12/2024
25.0.1 109 2/28/2024
25.0.0 130 2/16/2024
24.0.1 117 2/12/2024
24.0.0 116 2/12/2024
23.0.0 268 12/14/2023
22.1.0 719 12/9/2023
22.0.2 605 12/1/2023
22.0.1 142 11/16/2023
22.0.0 105 11/14/2023
21.1.0 1,096 10/9/2023
21.0.4 182 9/15/2023
21.0.3 185 7/9/2023
21.0.2 153 7/6/2023
21.0.1 504 5/27/2023
21.0.0 394 4/15/2023
20.2.4 234 3/27/2023
20.2.3 242 3/17/2023
20.2.2 227 3/14/2023
20.2.1 831 3/11/2023
20.2.0 212 3/7/2023
20.1.6 255 2/23/2023
20.1.5 268 2/9/2023
20.1.4 493 1/28/2023
20.1.3 363 12/21/2022
20.1.2 309 12/14/2022
20.1.1 319 12/12/2022
20.1.0 338 12/4/2022
20.0.4 332 11/30/2022
20.0.3 661 10/28/2022
20.0.2 410 10/26/2022
20.0.1 451 10/21/2022
20.0.0 550 10/1/2022
19.4.1 549 9/10/2022
19.4.0 486 9/2/2022
19.3.0 484 8/23/2022
19.2.2 486 8/11/2022
19.2.1 495 8/6/2022
19.2.0 572 7/24/2022
19.1.4 1,040 5/23/2022
19.1.3 474 5/22/2022
19.1.2 490 5/18/2022
19.1.1 791 4/28/2022
19.1.0 1,009 4/10/2022
1.6.3 788 4/6/2022
1.6.2 2,454 3/30/2022
1.6.1 465 3/30/2022
1.6.0 464 3/30/2022
1.5.0 741 2/8/2022
1.4.1 729 2/8/2022
1.4.0 476 2/7/2022
1.3.2 500 2/1/2022
1.3.1 505 1/31/2022
1.3.0 474 1/31/2022
1.2.2 465 1/31/2022
1.2.1 458 1/31/2022
1.2.0 475 1/31/2022
1.1.0 473 1/31/2022
1.0.0 1,085 1/4/2021