⚠ Deprecated: Legacy
This library uses the legacy client WindowsAzure.Storage package which has been deprecated and split into multiple client libraries (Azure.Storage.Blobs, Azure.Data.Tables, etc). Suggested Alternatives For Azure Blob storage use: Audit.NET.AzureStorageBlobs For Azure Table storage use: Audit.NET.AzureStorageTables
Suggested alternative: Audit.NET.AzureStorageBlobs
Store Audit.NET Logs into an Azure Blob Storage
$ dotnet add package Audit.NET.AzureStorageAzure Blob and Azure Table storage providers for Audit.NET library (An extensible framework to audit executing operations in .NET).
Store the audit events in an Azure Storage container, as Blob files in JSON format, or as rows on an Azure Table.
NuGet Package To install the package run the following command on the Package Manager Console:
PM> Install-Package Audit.NET.AzureStorage
Warning
This library has been deprecated.
This library uses the legacy client WindowsAzure.Storage package which has been deprecated and split into multiple client libraries (Azure.Storage.Blobs, Azure.Data.Tables, etc).
Suggested Alternatives
Audit.NET.AzureStorageBlobsAudit.NET.AzureStorageTablesPlease see the Audit.NET Readme
Set the static Audit.Core.Configuration.DataProvider property to set one of the Azure Storage data providers, or call the UseAzureBlobStorage()/UseAzureTableStorage()
methods on the fluent configuration. This should be done before any AuditScope creation, i.e. during application startup.
Stores each audit event as a BLOB file with the JSON representation of the Audit Event.
Using a connection string:
Audit.Core.Configuration.Setup()
.UseAzureBlobStorage(config => config
.ConnectionString("DefaultEndpointsProtocol=https;AccountName=your account;AccountKey=your key")
.ContainerName("event")
.BlobName(ev => $"{ev.StartDate:yyyy-MM}/{ev.Environment.UserName}/{Guid.NewGuid()}.json")
.WithAccessTier(StandardBlobTier.Cool)
.WithMetadata(ev => new Dictionary<string, string>() { { "user", ev.Environment.UserName } }));
Using Azure Active Directory (authentication token):
Audit.Core.Configuration.Setup()
.UseAzureBlobStorage(config => config
.AzureActiveDirectory(adConfig => adConfig
.AccountName("your account")
.TenantId("your tenant ID"))
.ContainerName("event")
.BlobName(ev => $"{Guid.NewGuid()}.json"));
Depending on the authentication method, you can call one of the following two methods:
ConnectionString: To use Account Access Key or SAS authentication via an Azure Storage connection string.AzureActiveDirectory: To use Azure Active Directory authentication via access tokens acquired automatically.When using Azure Active Directory authentication you can provide the following configuration to AzureActiveDirectory() method:
AccountName: The Account Name of your Azure Storage.
TenantId: The Tenant ID, this is your Azure Active Directory ID. See How to get it.
AuthConnectionString: (Optional) Specifies a custom connection string for the Token Provider. Check this for more information.
ResouceUrl: (Optional) Specifies a custom resource URL to acquire the tokens for. By default the Azure Storage resource ID https://storage.azure.com/ is used.
EndpointSuffix: (Optional) Specifies a custom DNS endpoint suffix to use for the storage services. Default is core.windows.net.
UseHttps: (Optional) Specifies whether to use HTTPS to connect to storage service endpoints. Default is true.
ContainerName/ContainerNameBuilder: The container name to use (see the naming restrictions here). By default, "event" is used as the container name.BlobName: A function that takes an Audit Event and returns a unique blob name for the event. The resulting name can include path information (slash separated sub-folders). By default, a random Guid is used as the blob name.WithAccessTier: (optional) A function that takes an Audit Event and returns the Standard BLOB Access Tier to set after the blob upload.
Note that using this setting implies that each upload will require two calls: one to upload the blob, and another one to set the access tier.WithMetadata: (optional) A function that takes an Audit Event and returns a set of key-value pairs to be associated with the blob storage resource.This provider implements GetEvent and GetEventAsync methods to obtain an audit event by id:
var event = blobDataProvider.GetEvent("eventId");
Stores each audit event as a new row on an Azure Table, allowing to dynamically configure the columns.
Configuration example:
Audit.Core.Configuration.DataProvider = new AzureTableDataProvider()
{
ConnectionString = "DefaultEndpointsProtocol=https;AccountName=your account;AccountKey=your key",
TableName = "Events",
TableEntityMapper = ev => new AuditEventTableEntity(ev)
};
Or by using the fluent configuration API via UseAzureTableStorage method:
Audit.Core.Configuration.Setup()
.UseAzureTableStorage(_ => _
.ConnectionString("DefaultEndpointsProtocol=https;AccountName=your account;AccountKey=your key")
.TableName("Events")
.EntityMapper(ev => new AuditEventTableEntity(ev)));
You can set the entity mapper to return any class implementing ITableEntity, as the provided default AuditEventTableEntity.
As an alternative, you can use EntityBuilder() method to configure the columns mapping:
Audit.Core.Configuration.Setup()
.UseAzureTableStorage(_ => _
.ConnectionString("DefaultEndpointsProtocol=https;AccountName=your account;AccountKey=your key")
.TableName("Events")
.EntityBuilder(e => e
.PartitionKey(ev => $"Events{ev.StartDate:yyyyMM}")
.RowKey(ev => Guid.NewGuid().ToString())
.Columns(c => c.FromObject(ev => new { Date = ev.StartDate, AuditEventJson = ev.ToJson() }))));
Mandatory:
Optional:
The Azure Table data provider does not implements GetEvent nor GetEventAsync methods.
Entity Framework Extensions and Dapper Plus are major sponsors and are proud to contribute to the development of Audit.NET
Combine the power of auditing with the speed of Bulk Operations to get the best of both worlds — audit and performance.