public static LoggerConfiguration ConfigureConsole(this LoggerConfiguration config, ComfyLoggerOptions options) { if (options.WriteToConsole) { return(config.WriteTo.Console()); } return(config); }
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); }
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); });
public static Uri GetConnectionUri(ComfyLoggerOptions options) => new UriBuilder(options.LoggerConfig.LoggerConnectionOptions.Scheme, options.LoggerConfig.LoggerConnectionOptions.Url, options.LoggerConfig.LoggerConnectionOptions.Port).Uri;