public static LoggerConfiguration CreateAzureBlobOrEventHubConfiguration(this SerilogLargeAuditEventClientConfiguration config, BlobServiceClient blobServiceClient)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var configBuilder = new LoggerConfiguration()
                                .Enrich.With(new EventIdEnricher())
                                .Enrich.With(new CreatedDateTimeEnricher())
                                .Enrich.WithProperty("_EventSource", config.EventSource)
                                .WriteTo.AzureBlobOrEventHub(
                eventHubConnectionString: config.EventHubConnectionString,
                eventHubName: config.AuditEventTopic,
                eventSizeLimitInBytes: config.EventSizeLimitinBytes,
                blobServiceClient: blobServiceClient,
                storageContainerName: config.StorageContainerName,
                formatter: new Serilog.Formatting.Compact.CompactJsonFormatter());

            if (config.EnrichFromLogContext == true)
            {
                configBuilder = configBuilder.Enrich.FromLogContext();
            }

            return(configBuilder);
        }
Пример #2
0
 public SerilogLargeAuditEventClient(SerilogLargeAuditEventClientConfiguration config, BlobServiceClient blobServiceClient)
 {
     this.customSinkLogger  = config.CreateAzureBlobOrEventHubConfiguration(blobServiceClient).CreateLogger();
     this.disposeLogger     = true;
     this.auditToCustomSink = new SerilogCustomSinkLoggerAudit(this.customSinkLogger);
 }