From 044645832860d9a8eb54845e0e477103a85bc38c Mon Sep 17 00:00:00 2001 From: Stefano Pian Date: Wed, 20 Dec 2017 16:59:21 +0100 Subject: [PATCH 1/2] Added logLevelSwitch option --- .../LoggerConfigurationElasticSearchExtensions.cs | 15 +++++++++++---- .../ElasticSearch/ElasticsearchSinkOptions.cs | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs index a7a3166f..5308b33e 100644 --- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs +++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs @@ -55,7 +55,11 @@ public static LoggerConfiguration Elasticsearch( ? (ILogEventSink)new ElasticsearchSink(options) : new DurableElasticsearchSink(options); - return loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel ?? LevelAlias.Minimum); + return loggerSinkConfiguration.Sink( + sink, + restrictedToMinimumLevel : options.MinimumLogEventLevel ?? LevelAlias.Minimum, + levelSwitch : options.LoggingLevelSwitch + ); } /// @@ -69,7 +73,8 @@ public static LoggerConfiguration Elasticsearch( /// /// /// - /// The minimum log event level required in order to write an event to the sink. + /// The minimum log event level required in order to write an event to the sink. Ignored when is specified. + /// A switch allowing the pass-through minimum level to be changed at runtime. /// /// /// @@ -89,7 +94,8 @@ public static LoggerConfiguration Elasticsearch( string bufferBaseFilename = null, long? bufferFileSizeLimitBytes = null, long bufferLogShippingInterval = 5000, - string connectionGlobalHeaders = null) + string connectionGlobalHeaders = null, + LoggingLevelSwitch loggingLevelSwitch = null) { if (string.IsNullOrEmpty(nodeUris)) throw new ArgumentNullException("nodeUris", "No Elasticsearch node(s) specified."); @@ -119,7 +125,8 @@ public static LoggerConfiguration Elasticsearch( options.BatchPostingLimit = batchPostingLimit; options.Period = TimeSpan.FromSeconds(period); options.InlineFields = inlineFields; - options.MinimumLogEventLevel = restrictedToMinimumLevel; + options.MinimumLogEventLevel = restrictedToMinimumLevel; + options.LoggingLevelSwitch = loggingLevelSwitch; if (!string.IsNullOrWhiteSpace(bufferBaseFilename)) { diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs index 9be9dcd9..515e60cf 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs @@ -128,10 +128,15 @@ public class ElasticsearchSinkOptions public bool InlineFields { get; set; } /// - /// The minimum log event level required in order to write an event to the sink. + /// The minimum log event level required in order to write an event to the sink. Ignored when LoggingLevelSwitch is specified. /// public LogEventLevel? MinimumLogEventLevel { get; set; } + /// + /// A switch allowing the pass-through minimum level to be changed at runtime. + /// + public LoggingLevelSwitch LoggingLevelSwitch { get; set; } + /// /// When passing a serializer unknown object will be serialized to object instead of relying on their ToString representation /// From 2ee6bccf6b6296a3e45532479cb8920c2e1a9686 Mon Sep 17 00:00:00 2001 From: Stefano Pian Date: Thu, 21 Dec 2017 10:40:31 +0100 Subject: [PATCH 2/2] 'loggingLevelSwitch' -> 'levelSwitch' as @nblumhardt recommended --- .../LoggerConfigurationElasticSearchExtensions.cs | 10 +++++----- .../Sinks/ElasticSearch/ElasticsearchSinkOptions.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs index 5308b33e..84444b77 100644 --- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs +++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs @@ -58,7 +58,7 @@ public static LoggerConfiguration Elasticsearch( return loggerSinkConfiguration.Sink( sink, restrictedToMinimumLevel : options.MinimumLogEventLevel ?? LevelAlias.Minimum, - levelSwitch : options.LoggingLevelSwitch + levelSwitch : options.LevelSwitch ); } @@ -73,8 +73,8 @@ public static LoggerConfiguration Elasticsearch( /// /// /// - /// The minimum log event level required in order to write an event to the sink. Ignored when is specified. - /// A switch allowing the pass-through minimum level to be changed at runtime. + /// The minimum log event level required in order to write an event to the sink. Ignored when is specified. + /// A switch allowing the pass-through minimum level to be changed at runtime. /// /// /// @@ -95,7 +95,7 @@ public static LoggerConfiguration Elasticsearch( long? bufferFileSizeLimitBytes = null, long bufferLogShippingInterval = 5000, string connectionGlobalHeaders = null, - LoggingLevelSwitch loggingLevelSwitch = null) + LoggingLevelSwitch levelSwitch = null) { if (string.IsNullOrEmpty(nodeUris)) throw new ArgumentNullException("nodeUris", "No Elasticsearch node(s) specified."); @@ -126,7 +126,7 @@ public static LoggerConfiguration Elasticsearch( options.Period = TimeSpan.FromSeconds(period); options.InlineFields = inlineFields; options.MinimumLogEventLevel = restrictedToMinimumLevel; - options.LoggingLevelSwitch = loggingLevelSwitch; + options.LevelSwitch = levelSwitch; if (!string.IsNullOrWhiteSpace(bufferBaseFilename)) { diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs index 515e60cf..a47b3152 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs @@ -135,7 +135,7 @@ public class ElasticsearchSinkOptions /// /// A switch allowing the pass-through minimum level to be changed at runtime. /// - public LoggingLevelSwitch LoggingLevelSwitch { get; set; } + public LoggingLevelSwitch LevelSwitch { get; set; } /// /// When passing a serializer unknown object will be serialized to object instead of relying on their ToString representation