Audit.NET.RavenDB 1.6.1

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.1
NuGet\Install-Package Audit.NET.RavenDB -Version 1.6.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="Audit.NET.RavenDB" Version="1.6.1" />
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.1
#r "nuget: Audit.NET.RavenDB, 1.6.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.
// Install Audit.NET.RavenDB as a Cake Addin
#addin nuget:?package=Audit.NET.RavenDB&version=1.6.1

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

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
25.0.4 131 3/24/2024
25.0.3 129 3/13/2024
25.0.2 88 3/12/2024
25.0.1 73 2/28/2024
25.0.0 87 2/16/2024
24.0.1 102 2/12/2024
24.0.0 78 2/12/2024
23.0.0 238 12/14/2023
22.1.0 96 12/9/2023
22.0.2 347 12/1/2023
22.0.1 119 11/16/2023
22.0.0 84 11/14/2023
21.1.0 787 10/9/2023
21.0.4 161 9/15/2023
21.0.3 156 7/9/2023
21.0.2 132 7/6/2023
21.0.1 376 5/27/2023
21.0.0 381 4/15/2023
20.2.4 212 3/27/2023
20.2.3 216 3/17/2023
20.2.2 202 3/14/2023
20.2.1 806 3/11/2023
20.2.0 199 3/7/2023
20.1.6 232 2/23/2023
20.1.5 259 2/9/2023
20.1.4 471 1/28/2023
20.1.3 333 12/21/2022
20.1.2 290 12/14/2022
20.1.1 289 12/12/2022
20.1.0 314 12/4/2022
20.0.4 311 11/30/2022
20.0.3 633 10/28/2022
20.0.2 389 10/26/2022
20.0.1 427 10/21/2022
20.0.0 528 10/1/2022
19.4.1 524 9/10/2022
19.4.0 467 9/2/2022
19.3.0 456 8/23/2022
19.2.2 465 8/11/2022
19.2.1 468 8/6/2022
19.2.0 549 7/24/2022
19.1.4 1,022 5/23/2022
19.1.3 448 5/22/2022
19.1.2 464 5/18/2022
19.1.1 770 4/28/2022
19.1.0 1,000 4/10/2022
1.6.3 764 4/6/2022
1.6.2 2,429 3/30/2022
1.6.1 442 3/30/2022
1.6.0 443 3/30/2022
1.5.0 729 2/8/2022
1.4.1 718 2/8/2022
1.4.0 453 2/7/2022
1.3.2 473 2/1/2022
1.3.1 478 1/31/2022
1.3.0 449 1/31/2022
1.2.2 445 1/31/2022
1.2.1 447 1/31/2022
1.2.0 446 1/31/2022
1.1.0 448 1/31/2022
1.0.0 1,063 1/4/2021