public KafkaSink(PeriodicSinkConfiguration sinkConfig, KafkaConfiguration kafkaConfig, string type)
            : base(sinkConfig.BatchSizeLimit, sinkConfig.Period)
        {
            var config = new Dictionary <string, object> {
                { "bootstrap.servers", string.Join(",", kafkaConfig.Brokers) }
            };

            this.topic    = kafkaConfig.Topic;
            this.producer = new Producer <Null, List <LogEventV1> >(config, null, new JsonSerializer <List <LogEventV1> >());
            this.type     = type;
        }
Esempio n. 2
0
        public static LoggerConfiguration Kafka(this LoggerSinkConfiguration loggerConfiguration, PeriodicSinkConfiguration sinkConfig, KafkaConfiguration kafkaConfig, string type)
        {
            var sink = new KafkaSink(sinkConfig, kafkaConfig, type);

            return(loggerConfiguration.Sink(sink));
        }
        public static ILoggingBuilder AddPetProjectLogging(this ILoggingBuilder builder, LogEventLevel minLevel, PeriodicSinkConfiguration sinkConfig, KafkaConfiguration kafkaConfig, string type, bool dispose = false)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var logger = new LoggerConfiguration()
                         .MinimumLevel.Is(minLevel)
                         .Enrich.FromLogContext()
                         .WriteTo.Kafka(sinkConfig, kafkaConfig, type)
                         .CreateLogger();

            builder.AddSerilog(logger, dispose);
            builder.SetMinimumLevel(minLevel.MapToNetCoreLogLevel());

            return(builder);
        }