A Serilog sink that writes events to Azure EventHubs
We removed the non-batching version of the sink because Azure Eventhub has terrible performance when logging synchronously, and logging towards it should always be performed in asynchronous batches.
var eventHubClient = EventHubClient.CreateFromConnectionString(eventHubConnectionString, "entityPath");
var logger = new LoggerConfiguration()
.WriteTo.Sink(new AzureEventHubBatchingSink(
eventHubClient: eventHubClient,
period: TimeSpan.FromSeconds(15),
...
.CreateLogger();
IMPORTANT! Since this sink is asyncronous it is vital that you properly flush all log messages, using the Log.CloseAndFlush() method, and if you are using sub-loggers then you need to manually dispose each sub-logger.