コード例 #1
0
        public static LoggerConfiguration ConfigureConsole(this LoggerConfiguration config,
                                                           ComfyLoggerOptions options)
        {
            if (options.WriteToConsole)
            {
                return(config.WriteTo.Console());
            }

            return(config);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #4
0
        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);
        });
コード例 #5
0
 public static Uri GetConnectionUri(ComfyLoggerOptions options)
 => new UriBuilder(options.LoggerConfig.LoggerConnectionOptions.Scheme,
                   options.LoggerConfig.LoggerConnectionOptions.Url,
                   options.LoggerConfig.LoggerConnectionOptions.Port).Uri;