public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var configSource = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>()) .AddCommandLine(args) .Build(); var config = configSource.Get <AppConfig>(); if (string.IsNullOrEmpty(config?.EventHubsConnectionString)) { Log.Fatal("Please provide the connection string argument. E.g. {Args}", "--EventHubsConnectionString=\"XXX\""); return; } var clientConfig = new SerilogAzureEventHubsAuditClientConfiguration { ConnectionString = config.EventHubsConnectionString, EventSource = config.EventSource ?? $"Consumption client sample on {Environment.MachineName}", }; var eventHubsTopic = clientConfig.AuditEventTopic; var eventHubsHost = new Microsoft.Azure.EventHubs.EventHubsConnectionStringBuilder(clientConfig.ConnectionString).Endpoint; using (var auditClient = new SerilogAzureEventHubsAuditClient(clientConfig)) { switch (config.Kind) { case ConsumptionKind.ReserveAndReleaseCapacity: RecordReservedAndReleaseCapacity( auditClient, numberOfEvents: config.NumberOfEvents, numberOfThreads: config.NumberOfThreads, eventHubsTopic: eventHubsTopic, eventHubsHost: $"{eventHubsHost}", meterData: config.MeterData, data: config.ReservedAndReleaseCapacityData); break; case ConsumptionKind.ConsumedAmount: RecordConsumedAmount( auditClient, numberOfEvents: config.NumberOfEvents, numberOfThreads: config.NumberOfThreads, eventHubsTopic: eventHubsTopic, eventHubsHost: $"{eventHubsHost}", meterData: config.MeterData, consumedAmountData: config.ConsumedAmountData); break; default: throw new Exception($"Unknown consumption type: {config.Kind}"); } } }
public void SendsTheAuditEventEncodedAsCompactJsonDataImmediately() { var client = new SerilogAzureEventHubsAuditClient( new SerilogAzureEventHubsAuditClientConfiguration { ConnectionString = "intentionally-invalid", EnrichFromLogContext = true, }); using (LogContext.PushProperty("LogContext", "AValueOnLogContext")) { client .ForContext("ForContext", "AValueViaForContext") .Write("Hey hey, from {Source}", nameof(SerilogAzureEventHubsAuditClientTests)); } }