Audit.NET.Firestore 31.0.1

dotnet add package Audit.NET.Firestore --version 31.0.1
                    
NuGet\Install-Package Audit.NET.Firestore -Version 31.0.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.Firestore" Version="31.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Audit.NET.Firestore" Version="31.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Audit.NET.Firestore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Audit.NET.Firestore --version 31.0.1
                    
#r "nuget: Audit.NET.Firestore, 31.0.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.
#:package Audit.NET.Firestore@31.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Audit.NET.Firestore&version=31.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Audit.NET.Firestore&version=31.0.1
                    
Install as a Cake Tool

Audit.NET.Firestore

Google Cloud Firestore provider for Audit.NET library. (An extensible framework to audit executing operations in .NET).

Store the audit events in a Google Cloud Firestore database as documents in a collection.

Install

NuGet Package

PM> Install-Package Audit.NET.Firestore

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

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

Basic Configuration

Using the fluent configuration API:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .Collection("AuditEvents"));

Or directly assigning the data provider:

Audit.Core.Configuration.DataProvider = new Audit.Firestore.Providers.FirestoreDataProvider()
{
    ProjectId = "your-project-id",
    Collection = "AuditEvents"
};

Authentication

The Firestore provider supports several authentication methods:

Default Application Credentials

If running on Google Cloud Platform or with properly configured environment variables:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .Collection("AuditEvents"));
Service Account Key File

Using a JSON credentials file:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .CredentialsFromFile("path/to/credentials.json")
        .Collection("AuditEvents"));
Service Account JSON String

Using credentials as a JSON string:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .CredentialsFromJson(credentialsJsonString)
        .Collection("AuditEvents"));
Custom FirestoreDb Instance

Using a pre-configured FirestoreDb instance:

var firestoreDb = FirestoreDb.Create("your-project-id");
Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .FirestoreDb(firestoreDb)
        .Collection("AuditEvents"));

Provider Options

  • ProjectId: The Google Cloud project ID (required unless using custom FirestoreDb).
  • Database: The Firestore database name. Default is "(default)".
  • Collection: The Firestore collection name for storing audit events. Can be a fixed string or a function of the audit event.
  • CredentialsFilePath: Path to the service account credentials JSON file.
  • CredentialsJson: Service account credentials as a JSON string.
  • FirestoreDb: A custom pre-configured FirestoreDb instance.
  • IdBuilder: A function that returns the document ID to use for a given audit event. By default, Firestore generates the ID automatically.
  • SanitizeFieldNames: Whether to sanitize field names by replacing dots with underscores. Default is false.
  • ExcludeNullValues: Whether to exclude null values from the stored audit event data. Default is false.

Advanced Configuration

Dynamic Collection Names

You can configure collection names based on the audit event:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .Collection(auditEvent => $"Audit_{auditEvent.EventType}")
        .IdBuilder(auditEvent => $"{auditEvent.EventType}_{DateTime.UtcNow.Ticks}"));
Multiple Databases

Firestore supports multiple databases per project:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .Database("audit-database")
        .Collection("AuditEvents"));

Querying Events

The Firestore data provider includes methods to retrieve and query audit events.

Get an Event by ID

var event = firestoreDataProvider.GetEvent("eventId");

Query Events (In-Memory)

The QueryEvents() method returns an IQueryable that loads all events into memory:

var events = firestoreDataProvider.QueryEvents()
    .Where(ev => ev.EventType == "Login")
    .OrderByDescending(ev => ev.StartDate)
    .Take(10)
    .ToList();

Query Events (Firestore Native)

For better performance with large collections, use the native Firestore query methods:

// Query with Firestore filters
var events = await firestoreDataProvider.QueryEventsAsync(query => query
    .WhereEqualTo("EventType", "Login")
    .WhereGreaterThan("StartDate", DateTime.UtcNow.AddDays(-7))
    .OrderByDescending("StartDate")
    .Limit(10));

Access Native Firestore Collection

You can access the native Firestore collection reference for advanced operations:

var collection = firestoreDataProvider.GetFirestoreCollection();
var query = collection.WhereEqualTo("Environment.UserName", "admin");
var snapshot = await query.GetSnapshotAsync();

Field Name Restrictions

Firestore has restrictions on field names (cannot contain dots). You can enable automatic sanitization to replace dots with underscores:

Audit.Core.Configuration.Setup()
    .UseFirestore(config => config
        .ProjectId("your-project-id")
        .SanitizeFieldNames(true)); // Automatically replace dots with underscores

Output Sample

Audit events are stored as Firestore documents with the following structure:

{
  "_timestamp": "2024-01-10T10:30:45Z",
  "EventType": "Order:Update",
  "Environment": {
    "UserName": "john.doe",
    "MachineName": "WORKSTATION01",
    "DomainName": "CORPORATE",
    "CallingMethodName": "OrderService.UpdateOrder",
    "Culture": "en-US"
  },
  "StartDate": "2024-01-10T10:30:45.123Z",
  "EndDate": "2024-01-10T10:30:45.789Z",
  "Duration": 666,
  "Target": {
    "Type": "Order",
    "Old": {
      "OrderId": 12345,
      "Status": "Pending",
      "Total": 150.00
    },
    "New": {
      "OrderId": 12345,
      "Status": "Approved",
      "Total": 150.00
    }
  },
  "CustomFields": {
    "ApprovedBy": "manager@company.com",
    "ApprovalReason": "Valid payment method"
  }
}

Performance Considerations

  1. Document Size: Firestore documents have a maximum size of 1MB. Large audit events may exceed this limit.

  2. Indexing: Create composite indexes for fields you frequently query together.

  3. Collection Size: For high-volume auditing, consider:

    • Using dynamic collection names to partition data
    • Implementing a retention policy to delete old events
    • Using batch operations for bulk inserts
  4. Field Names: Field name sanitization (dots to underscores) adds a small overhead. Enable it only if your field names contain dots.

Connection Testing

You can test the Firestore connection:

var provider = new FirestoreDataProvider()
{
    ProjectId = "your-project-id"
};

await provider.TestConnectionAsync();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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

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
31.0.1 11 8/28/2025
31.0.0 81 8/22/2025
30.1.3 115 8/19/2025
30.1.2 119 8/14/2025
30.1.1 123 8/13/2025
30.0.2 226 6/26/2025