コード例 #1
0
        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());
        }
コード例 #2
0
        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"));
        }