Exemplo n.º 1
0
        public static LoggerConfiguration CreateDefaultConfiguration(this SerilogAzureEventHubsAuditClientConfiguration config)
        {
            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)
                                .AuditTo.AzureEventHub(
                formatter: new Serilog.Formatting.Compact.CompactJsonFormatter(),
                connectionString: config.ConnectionString,
                eventHubName: config.AuditEventTopic)
            ;

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

            return(configBuilder);
        }
Exemplo n.º 2
0
 public SerilogAzureEventHubsAuditClient(SerilogAzureEventHubsAuditClientConfiguration config)
 {
     this.logger        = config.CreateDefaultConfiguration().CreateLogger();
     this.disposeLogger = true;
     this.audit         = new SerilogLoggerAudit(this.logger);
 }