private static void SetupServices(IServiceCollection serviceCollection, IStringKeyValueStore store) { SetupLogging(serviceCollection, store); var kafkaConfig = new KafkaConfiguration { Brokers = store.GetAndConvertValue <string>("KafkaConfiguration/Brokers").Split(','), Topic = store.GetAndConvertValue <string>("KafkaConfiguration/Topic"), ConsumerGroupId = store.GetAndConvertValue <string>("KafkaConfiguration/ConsumerGroupId") }; var elasticConfig = new ElasticClientConfiguration { Address = store.GetAndConvertValue <string>("ElasticConfiguration/Address") }; // this call must happen after previous two (addsingleton of kafkaconfig + elasticconfig) serviceCollection.AddPetProjectElasticLogConsumer(kafkaConfig, elasticConfig); }
private static void SetupLogging(IServiceCollection serviceCollection, IStringKeyValueStore store) { var kafkaConfig = new Framework.Logging.Producer.KafkaConfiguration { Brokers = store.GetAndConvertValue <string>("KafkaConfiguration/Brokers").Split(','), Topic = store.GetAndConvertValue <string>("KafkaConfiguration/Topic") }; var sinkConfig = new PeriodicSinkConfiguration { BatchSizeLimit = store.GetAndConvertValue <int>("Logging/BatchSizeLimit"), Period = TimeSpan.FromMilliseconds(store.GetAndConvertValue <int>("Logging/PeriodMs")) }; var logLevel = store.GetAndConvertValue <LogEventLevel>("Logging/LogLevel"); var logType = store.GetAndConvertValue <string>("Logging/LogType"); serviceCollection.AddLogging(builder => builder.AddPetProjectLogging(logLevel, sinkConfig, kafkaConfig, logType, true).AddConsole()); serviceCollection.TryAddSingleton <ILogger>(sp => sp.GetRequiredService <ILoggerFactory>().CreateLogger("No category")); }
public static ILoggingBuilder SetupLogging(this ILoggingBuilder loggingBuilder, IStringKeyValueStore configStore) { var kafkaConfig = new KafkaConfiguration { Brokers = configStore.GetAndConvertValue <string>("Logging/KafkaConfiguration/Brokers").Split(','), Topic = configStore.GetAndConvertValue <string>("Logging/KafkaConfiguration/Topic") }; var sinkConfig = new PeriodicSinkConfiguration { BatchSizeLimit = configStore.GetAndConvertValue <int>("Logging/BatchSizeLimit"), Period = TimeSpan.FromMilliseconds(configStore.GetAndConvertValue <int>("Logging/PeriodMs")) }; var logLevel = configStore.GetAndConvertValue <LogEventLevel>("Logging/LogLevel"); var logType = configStore.GetAndConvertValue <string>("Logging/LogType"); return(loggingBuilder.AddPetProjectLogging(logLevel, sinkConfig, kafkaConfig, logType, true).AddConsole().AddDebug()); }