Audit.NET.AzureCosmos 25.0.4

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

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

Audit.NET.AzureCosmos

Azure Cosmos DB (Document DB SQL API) provider for Audit.NET library. (An extensible framework to audit executing operations in .NET)

Store the audit events in an Azure Cosmos DB collection, in JSON format.

Install

NuGet Package To install the package run the following command on the Package Manager Console:

PM> Install-Package Audit.NET.AzureCosmos

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

Set the static Audit.Core.Configuration.DataProvider property to set the Cosmos DB data provider, or use the UseAzureCosmos method on the fluent configuration. This should be done before any AuditScope creation, i.e. during application startup.

For example:

Audit.Core.Configuration.DataProvider = new Audit.AzureCosmos.Providers.AzureCosmosDataProvider(config => config
    .Endpoint("https://mycompany.documents.azure.com:443/")
    .AuthKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==")
    .Database("Audit")
    .Container("logs")
    .WithId(_ => Guid.NewGuid().ToString().ToUpper()));

Or by using the fluent configuration API:

Audit.Core.Configuration.Setup()
    .UseAzureCosmos(config => config
        .Endpoint("https://mycompany.documents.azure.com:443/")
        .AuthKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==")
        .Database("Audit")
        .Container("logs")
        .ClientOptions(options => { options.ConnectionMode = ConnectionMode.Gateway; }));

Provider options

Mandatory config with an Endpoint and an AuthKey:

  • Endpoint / EndpointBuilder: The Azure Cosmos endpoint URL.
  • AuthKey / AuthKeyBuilder: The Auth Key to use.

Or with a previously configured instance of DocumentClient/CosmosClient:

  • DocumentClient / CosmosClient: Sets an already configured document/cosmos client.

Container seetings:

  • Database / DatabaseBuilder: The audit database name.
  • Container / ContainerBuilder: The events container name.
  • WithId / IdBuilder: A func that returns the document id to use for a given audit event. By default it will generate a new random id.

Query events

This provider implements GetEvent and GetEventAsync methods to obtain an audit event by id and partition key. Note that if your container has a partition key defined, you need to provide both id and partition key:

var event = auditDataProvider.GetEvent(("eventId", "partitionValue"));

or using the overload on the concrete AzureCosmosDataProvider:

var event = azureCosmosDataProvider.GetEvent("eventId", "partitionValue");

The Azure Cosmos data provider also includes support for querying the events collection.

Use the QueryEvents() method on AzureCosmosDataProvider class to run LINQ queries against the audit events.

For example, to get the top 10 most time-consuming events for a specific machine:

IQueryable<AuditEvent> query = azureCosmosDataProvider.QueryEvents()
	.Where(ev => ev.Environment.MachineName == "HP")
	.OrderByDescending(ev => ev.Duration)
	.Take(10);

Also you can use the EnumerateEvents() method to run SQL-like queries. For example the previous query can be written as:

IEnumerable<AuditEvent> events = cosmosDbDataProvider.EnumerateEvents(
       @"SELECT TOP 10 * 
         FROM c 
         WHERE c.Environment.MachineName = 'HP' 
         ORDER BY c.Duration DESC");

This post contains information about the SQL query syntax supported by Azure Document DB.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Audit.NET.AzureCosmos:

Package Downloads
Solhigson.Framework.AzureCosmosDb

Azure Cosmos Db Client and NLog Target

AuditLogger

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
25.0.4 108 3/24/2024
25.0.3 135 3/13/2024
25.0.2 139 3/12/2024
25.0.1 190 2/28/2024
25.0.0 1,856 2/16/2024
24.0.1 151 2/12/2024
24.0.0 83 2/12/2024
23.0.0 4,216 12/14/2023
22.1.0 107 12/9/2023
22.0.2 1,232 12/1/2023
22.0.1 387 11/16/2023
22.0.0 113 11/14/2023
21.1.0 3,012 10/9/2023
21.0.4 763 9/15/2023
21.0.3 9,917 7/9/2023
21.0.2 3,563 7/6/2023
21.0.1 1,141 5/27/2023
21.0.0 1,010 4/15/2023
20.2.4 7,143 3/27/2023
20.2.3 547 3/17/2023
20.2.2 288 3/14/2023
20.2.1 260 3/11/2023
20.2.0 337 3/7/2023
20.1.6 3,940 2/23/2023
20.1.5 3,276 2/9/2023
20.1.4 3,669 1/28/2023
20.1.3 933 12/21/2022
20.1.2 377 12/14/2022
20.1.1 442 12/12/2022
20.1.0 470 12/4/2022
20.0.4 406 11/30/2022
20.0.3 28,743 10/28/2022
20.0.2 5,655 10/26/2022
20.0.1 4,082 10/21/2022
20.0.0 1,528 10/1/2022
19.4.1 1,867 9/10/2022
19.4.0 1,213 9/2/2022
19.3.0 1,427 8/23/2022
19.2.2 1,187 8/11/2022
19.2.1 10,569 8/6/2022
19.2.0 10,766 7/24/2022
19.1.4 31,546 5/23/2022
19.1.3 518 5/22/2022
19.1.2 667 5/18/2022
19.1.1 5,835 4/28/2022
19.1.0 25,243 4/10/2022
19.0.7 7,331 3/13/2022
19.0.6 477 3/7/2022
19.0.5 5,560 1/28/2022
19.0.4 542 1/23/2022
19.0.3 4,510 12/14/2021
19.0.2 1,216 12/11/2021
19.0.1 10,311 11/20/2021
19.0.0 487 11/11/2021
19.0.0-rc.net60.2 161 9/26/2021
19.0.0-rc.net60.1 195 9/16/2021
18.1.6 3,765 9/26/2021
18.1.5 4,278 9/7/2021
18.1.4 389 9/6/2021
18.1.3 2,676 8/19/2021
18.1.2 552 8/8/2021
18.1.1 495 8/5/2021
18.1.0 518 8/1/2021
18.0.1 549 7/30/2021
18.0.0 512 7/26/2021
17.0.8 648 7/7/2021
17.0.7 7,839 6/16/2021
17.0.6 509 6/5/2021
17.0.5 492 5/28/2021
17.0.4 1,038 5/4/2021
17.0.3 478 5/1/2021
17.0.2 477 4/22/2021