Ejemplo n.º 1
0
        public static void Validate(LogstashOption logstashOption)
        {
            Assert.NotNull(logstashOption.Mode, nameof(logstashOption.Mode));
            switch (logstashOption.Mode)
            {
            case "tcp":
                Assert.NotNull(logstashOption.LogstashUrl, nameof(logstashOption.LogstashUrl));
                break;

            case "http":
                Assert.NotNull(logstashOption.IP, nameof(logstashOption.IP));
                Assert.NotNull(logstashOption.Port, nameof(logstashOption.Port));
                break;
            }
        }
Ejemplo n.º 2
0
        public static void AddLogstashLogger(this IServiceCollection services, Action <LogstashOption> action)
        {
            var logstashOption = new LogstashOption();

            if (action != null)
            {
                action(logstashOption);
            }
            else
            {
                IConfiguration configuration = services.GetServiceCollection <IConfiguration>();
                logstashOption = configuration.GetSection("Logger").Get <LogstashOption>() ?? logstashOption;
            }
            Validate(logstashOption);
            services.AddSingleton(p => Options.Create(logstashOption));
            services.AddSingleton(typeof(ILogger <>), typeof(LogstashLogger <>));
        }