Esempio n. 1
0
        public static LoggerConfiguration ConfigureConsole(this LoggerConfiguration config,
                                                           ComfyLoggerOptions options)
        {
            if (options.WriteToConsole)
            {
                return(config.WriteTo.Console());
            }

            return(config);
        }
Esempio n. 2
0
        public static LoggerConfiguration ConfigureDefaultSettings(this LoggerConfiguration config,
                                                                   ComfyLoggerOptions options)
        {
            if (!Enum.TryParse <LogEventLevel>(options.MinimumLevel, true, out var minimumLevel))
            {
                minimumLevel = LogEventLevel.Information;
            }

            config.MinimumLevel.Is(minimumLevel);

            return(config);
        }
Esempio n. 3
0
        public static LoggerConfiguration ConfigureElasticSearch(this LoggerConfiguration config,
                                                                 ComfyLoggerOptions options)
        {
            if (options.Enabled && options.LogStorage == LogStorage.ElasticSearch)
            {
                return(config.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(GetConnectionUri(options))
                {
                    IndexFormat = options.LoggerConfig.IndexPattern,
                    InlineFields = true
                }));
            }

            return(config);
        }
        public static IWebHostBuilder UseComfyLogger(this IWebHostBuilder builder)
        => builder.UseSerilog((webHostBuilderContext, loggerConfiguration)
                              => {
            var appOptions = new AppOptions();
            webHostBuilderContext.Configuration.GetSection("app")
            .Bind(appOptions);

            var loggerOptions = new ComfyLoggerOptions();
            webHostBuilderContext.Configuration.GetSection("logger")
            .Bind(loggerOptions);

            loggerConfiguration
            .Enrich.FromLogContext()
            .Enrich.WithMachineName()
            .Enrich.WithProperty("applicationName", appOptions.Name)
            .ConfigureDefaultSettings(loggerOptions)
            .ConfigureConsole(loggerOptions)
            .ConfigureElasticSearch(loggerOptions);
        });
Esempio n. 5
0
 public static Uri GetConnectionUri(ComfyLoggerOptions options)
 => new UriBuilder(options.LoggerConfig.LoggerConnectionOptions.Scheme,
                   options.LoggerConfig.LoggerConnectionOptions.Url,
                   options.LoggerConfig.LoggerConnectionOptions.Port).Uri;