Audit.NET.AzureCosmos 27.1.0

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

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

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
27.2.0 36 11/23/2024
27.1.1 1,230 10/28/2024
27.1.0 89 10/24/2024
27.0.3 2,536 9/25/2024
27.0.2 347 9/19/2024
27.0.1 1,020 9/4/2024
27.0.0 186 9/3/2024
26.0.1 277 8/22/2024
26.0.0 2,102 7/19/2024
25.0.7 4,701 7/4/2024
25.0.6 2,020 6/24/2024
25.0.5 561 6/18/2024
25.0.4 21,626 3/24/2024
25.0.3 236 3/13/2024
25.0.2 208 3/12/2024
25.0.1 358 2/28/2024
25.0.0 3,088 2/16/2024
24.0.1 186 2/12/2024
24.0.0 114 2/12/2024
23.0.0 5,234 12/14/2023
22.1.0 148 12/9/2023
22.0.2 1,273 12/1/2023
22.0.1 1,281 11/16/2023
22.0.0 147 11/14/2023
21.1.0 3,053 10/9/2023
21.0.4 797 9/15/2023
21.0.3 12,366 7/9/2023
21.0.2 4,781 7/6/2023
21.0.1 1,193 5/27/2023
21.0.0 1,041 4/15/2023
20.2.4 9,236 3/27/2023
20.2.3 583 3/17/2023
20.2.2 318 3/14/2023
20.2.1 288 3/11/2023
20.2.0 407 3/7/2023
20.1.6 3,972 2/23/2023
20.1.5 4,904 2/9/2023
20.1.4 9,451 1/28/2023
20.1.3 967 12/21/2022
20.1.2 407 12/14/2022
20.1.1 467 12/12/2022
20.1.0 496 12/4/2022
20.0.4 446 11/30/2022
20.0.3 44,895 10/28/2022
20.0.2 7,229 10/26/2022
20.0.1 4,110 10/21/2022
20.0.0 1,560 10/1/2022
19.4.1 1,946 9/10/2022
19.4.0 1,656 9/2/2022
19.3.0 1,451 8/23/2022
19.2.2 1,218 8/11/2022
19.2.1 10,891 8/6/2022
19.2.0 12,715 7/24/2022
19.1.4 44,990 5/23/2022
19.1.3 554 5/22/2022
19.1.2 689 5/18/2022
19.1.1 7,719 4/28/2022
19.1.0 25,778 4/10/2022
19.0.7 8,687 3/13/2022
19.0.6 502 3/7/2022
19.0.5 5,596 1/28/2022
19.0.4 555 1/23/2022
19.0.3 4,628 12/14/2021
19.0.2 1,243 12/11/2021
19.0.1 10,344 11/20/2021
19.0.0 515 11/11/2021
19.0.0-rc.net60.2 179 9/26/2021
19.0.0-rc.net60.1 211 9/16/2021
18.1.6 4,006 9/26/2021
18.1.5 4,312 9/7/2021
18.1.4 412 9/6/2021
18.1.3 3,407 8/19/2021
18.1.2 580 8/8/2021
18.1.1 516 8/5/2021
18.1.0 554 8/1/2021
18.0.1 580 7/30/2021
18.0.0 533 7/26/2021
17.0.8 677 7/7/2021
17.0.7 7,960 6/16/2021
17.0.6 531 6/5/2021
17.0.5 506 5/28/2021
17.0.4 1,070 5/4/2021
17.0.3 513 5/1/2021
17.0.2 510 4/22/2021