Runpath.Extensions.Logging.AzureEventHubs 1.1.0

Azure Event Hubs logger provider implementation for Microsoft.Extensions.Logging.

Install-Package Runpath.Extensions.Logging.AzureEventHubs -Version 1.1.0
dotnet add package Runpath.Extensions.Logging.AzureEventHubs --version 1.1.0
<PackageReference Include="Runpath.Extensions.Logging.AzureEventHubs" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Runpath.Extensions.Logging.AzureEventHubs --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Runpath.Extensions.Logging.AzureEventHubs

Azure Event Hubs logger provider implementation for Microsoft.Extensions.Logging.

Getting started

Grab the package from NuGet, which will install all dependencies.

Install-Package Runpath.Extensions.Logging.AzureEventHubs

Usage

Extensive documentation for Microsoft.Extensions.Logging is available here and should cover most general aspects of this library.

Once your Azure Event Hubs resource is configured in Azure, you can then add its details to your configuration. The options expose 4 values that you can later use:

{
  "Logging": {
    "AzureEventHubs": {
      "Endpoint": "sb://example.servicebus.windows.net",
      "EntityPath": "my-hub",
      "SharedAccessKeyName": "my-key",
      "SharedAccessKey": "..."
    }
  }
}

Add this logger provider to your logging builder, supplying a delegate that creates an EventHubClient to your specifications, for example:

var services = new ServiceCollection();

services.AddLogging(builder => builder.AddAzureEventHubs(options =>
  options.TryGetConnectionString(out string connectionString)
    ? EventHubClient.CreateFromConnectionString(connectionString)
    : EventHubClient.CreateWithManagedServiceIdentity(options.Endpoint, options.EntityPath);
));

IAzureEventHubsLoggerFormatter

The formatting of event data is controlled by an instance of this interface. A default implementation is supplied out of the box, which formats events as JSON:

{
    "Timestamp": "2019-07-11T08:53:37.772Z",
    "LogLevel": "Information",
    "Category": "MyApplication",
    "EventId": 0,
    "Message": "Application started.",
    "Exception": null
}

To implement your own custom format, create your own implementation of IAzureEventHubsLoggerFormatter and replace the default instance in your service collection.

Custom implementations will have access to external scope data, provided by IExternalScopeProvider. To consume this, use the ForEachScope method exposed by IAzureEventHubsLoggerFormatter.

IAzureEventHubsLoggerProcessor

The processing of event data is controlled by an instance of this interface. A default implementation is supplied that implements a queue, offloads work to a background thread, and sends event data using batches.

The options expose 2 (optional) values to customise the thresholds and queuing logic of the default processor:

{
  "Logging": {
    "AzureEventHubs": {
      "QueueDepth": 1024,
      "QueueMode": "DropOldest"
    }
  }
}

QueueDepth must be a positive integer, and defaults to 1024. QueueMode can accept one of the values of BoundedChannelFullMode, and defaults to DropOldest.

To implement your own custom processing logic, create your own implementation of IAzureEventHubsLoggerProcessor and replace the default instance in your service collection.

Runpath.Extensions.Logging.AzureEventHubs

Azure Event Hubs logger provider implementation for Microsoft.Extensions.Logging.

Getting started

Grab the package from NuGet, which will install all dependencies.

Install-Package Runpath.Extensions.Logging.AzureEventHubs

Usage

Extensive documentation for Microsoft.Extensions.Logging is available here and should cover most general aspects of this library.

Once your Azure Event Hubs resource is configured in Azure, you can then add its details to your configuration. The options expose 4 values that you can later use:

{
  "Logging": {
    "AzureEventHubs": {
      "Endpoint": "sb://example.servicebus.windows.net",
      "EntityPath": "my-hub",
      "SharedAccessKeyName": "my-key",
      "SharedAccessKey": "..."
    }
  }
}

Add this logger provider to your logging builder, supplying a delegate that creates an EventHubClient to your specifications, for example:

var services = new ServiceCollection();

services.AddLogging(builder => builder.AddAzureEventHubs(options =>
  options.TryGetConnectionString(out string connectionString)
    ? EventHubClient.CreateFromConnectionString(connectionString)
    : EventHubClient.CreateWithManagedServiceIdentity(options.Endpoint, options.EntityPath);
));

IAzureEventHubsLoggerFormatter

The formatting of event data is controlled by an instance of this interface. A default implementation is supplied out of the box, which formats events as JSON:

{
    "Timestamp": "2019-07-11T08:53:37.772Z",
    "LogLevel": "Information",
    "Category": "MyApplication",
    "EventId": 0,
    "Message": "Application started.",
    "Exception": null
}

To implement your own custom format, create your own implementation of IAzureEventHubsLoggerFormatter and replace the default instance in your service collection.

Custom implementations will have access to external scope data, provided by IExternalScopeProvider. To consume this, use the ForEachScope method exposed by IAzureEventHubsLoggerFormatter.

IAzureEventHubsLoggerProcessor

The processing of event data is controlled by an instance of this interface. A default implementation is supplied that implements a queue, offloads work to a background thread, and sends event data using batches.

The options expose 2 (optional) values to customise the thresholds and queuing logic of the default processor:

{
  "Logging": {
    "AzureEventHubs": {
      "QueueDepth": 1024,
      "QueueMode": "DropOldest"
    }
  }
}

QueueDepth must be a positive integer, and defaults to 1024. QueueMode can accept one of the values of BoundedChannelFullMode, and defaults to DropOldest.

To implement your own custom processing logic, create your own implementation of IAzureEventHubsLoggerProcessor and replace the default instance in your service collection.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.0 111 12/6/2019
1.0.1 256 11/4/2019
1.0.0 575 8/2/2019