From bc504f42878aceb16ce37fd944a749a75e0b2320 Mon Sep 17 00:00:00 2001 From: vladz Date: Wed, 24 Jan 2018 14:53:40 +0200 Subject: [PATCH 1/4] Extend LoggerConfiguration.Elasticsearch with additional attributes --- ...ggerConfigurationElasticSearchExtensions.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs index 84444b77..d869c6b2 100644 --- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs +++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs @@ -79,6 +79,11 @@ public static LoggerConfiguration Elasticsearch( /// /// /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request + /// + /// + /// + /// + /// /// LoggerConfiguration object /// is . public static LoggerConfiguration Elasticsearch( @@ -95,7 +100,12 @@ public static LoggerConfiguration Elasticsearch( long? bufferFileSizeLimitBytes = null, long bufferLogShippingInterval = 5000, string connectionGlobalHeaders = null, - LoggingLevelSwitch levelSwitch = null) + LoggingLevelSwitch levelSwitch = null, + bool autoRegisterTemplate = false, + AutoRegisterTemplateVersion autoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv2, + bool overwriteTemplate = false, + int? numberOfShards = null, + int? numberOfReplicas = null) { if (string.IsNullOrEmpty(nodeUris)) throw new ArgumentNullException("nodeUris", "No Elasticsearch node(s) specified."); @@ -156,6 +166,12 @@ public static LoggerConfiguration Elasticsearch( options.ModifyConnectionSettings = (c) => c.GlobalHeaders(headers); } + options.AutoRegisterTemplate = autoRegisterTemplate; + options.AutoRegisterTemplateVersion = autoRegisterTemplateVersion; + options.OverwriteTemplate = overwriteTemplate; + options.NumberOfShards = numberOfShards; + options.NumberOfReplicas = numberOfReplicas; + return Elasticsearch(loggerSinkConfiguration, options); } } From a30be1abc6ca4cd05bbe24d4bc5cc6c9320b73eb Mon Sep 17 00:00:00 2001 From: vladz Date: Wed, 14 Feb 2018 13:08:20 +0200 Subject: [PATCH 2/4] added new Elasticsearch method and marked old as Obsolete --- ...gerConfigurationElasticSearchExtensions.cs | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs index d869c6b2..d49a05f9 100644 --- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs +++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs @@ -21,6 +21,7 @@ using Serilog.Events; using Serilog.Sinks.Elasticsearch; using System.Collections.Specialized; +using System.ComponentModel; namespace Serilog { @@ -62,6 +63,45 @@ public static LoggerConfiguration Elasticsearch( ); } + /// + /// Overload to allow basic configuration through AppSettings. + /// + /// Options for the sink. + /// A comma or semi column separated list of URIs for Elasticsearch nodes. + /// + /// + /// + /// + /// + /// + /// 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. + /// + /// + /// + /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request + [Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)] + public static LoggerConfiguration Elasticsearch( + this LoggerSinkConfiguration loggerSinkConfiguration, + string nodeUris, + string indexFormat, + string templateName, + string typeName, + int batchPostingLimit, + int period, + bool inlineFields, + LogEventLevel restrictedToMinimumLevel, + string bufferBaseFilename, + long? bufferFileSizeLimitBytes, + long bufferLogShippingInterval, + string connectionGlobalHeaders, + LoggingLevelSwitch levelSwitch) + { + return Elasticsearch(loggerSinkConfiguration, nodeUris, indexFormat, templateName, typeName, batchPostingLimit, period, inlineFields, restrictedToMinimumLevel, bufferBaseFilename, + bufferFileSizeLimitBytes, bufferLogShippingInterval, connectionGlobalHeaders, levelSwitch, 5, EmitEventFailureHandling.WriteToSelfLog, 100000, null, false, + AutoRegisterTemplateVersion.ESv2, false, RegisterTemplateRecovery.IndexAnyway, null, null, null); + } + /// /// Overload to allow basic configuration through AppSettings. /// @@ -79,9 +119,15 @@ public static LoggerConfiguration Elasticsearch( /// /// /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request + /// + /// + /// + /// /// - /// + /// /// + /// + /// /// /// /// LoggerConfiguration object @@ -101,9 +147,15 @@ public static LoggerConfiguration Elasticsearch( long bufferLogShippingInterval = 5000, string connectionGlobalHeaders = null, LoggingLevelSwitch levelSwitch = null, + int connectionTimeout = 5, + EmitEventFailureHandling emitEventFailure = EmitEventFailureHandling.WriteToSelfLog, + int queueSizeLimit = 100000, + string pipelineName = null, bool autoRegisterTemplate = false, AutoRegisterTemplateVersion autoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv2, bool overwriteTemplate = false, + RegisterTemplateRecovery registerTemplateFailure = RegisterTemplateRecovery.IndexAnyway, + string deadLetterIndexName = null, int? numberOfShards = null, int? numberOfReplicas = null) { @@ -166,12 +218,23 @@ public static LoggerConfiguration Elasticsearch( options.ModifyConnectionSettings = (c) => c.GlobalHeaders(headers); } + options.ConnectionTimeout = TimeSpan.FromSeconds(connectionTimeout); + options.EmitEventFailure = emitEventFailure; + options.QueueSizeLimit = queueSizeLimit; + options.PipelineName = pipelineName; + options.AutoRegisterTemplate = autoRegisterTemplate; options.AutoRegisterTemplateVersion = autoRegisterTemplateVersion; + options.RegisterTemplateFailure = registerTemplateFailure; options.OverwriteTemplate = overwriteTemplate; options.NumberOfShards = numberOfShards; options.NumberOfReplicas = numberOfReplicas; + if (!string.IsNullOrWhiteSpace(deadLetterIndexName)) + { + options.DeadLetterIndexName = deadLetterIndexName; + } + return Elasticsearch(loggerSinkConfiguration, options); } } From 37b01debba816218f882211ba02e992aaa823081 Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Sun, 25 Feb 2018 22:29:14 +0100 Subject: [PATCH 3/4] Added intellisense comments --- ...gerConfigurationElasticSearchExtensions.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs index d49a05f9..3a546f47 100644 --- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs +++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs @@ -119,17 +119,17 @@ public static LoggerConfiguration Elasticsearch( /// /// /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// The connection timeout (in seconds) when sending bulk operations to elasticsearch (defaults to 5). + /// Specifies how failing emits should be handled. + /// The maximum number of events that will be held in-memory while waiting to ship them to Elasticsearch. Beyond this limit, events will be dropped. The default is 100,000. Has no effect on durable log shipping. + /// Name the Pipeline where log events are sent to sink. Please note that the Pipeline should be existing before the usage starts. + /// When set to true the sink will register an index template for the logs in elasticsearch. + /// When using the AutoRegisterTemplate feature, this allows to set the Elasticsearch version. Depending on the version, a template will be selected. Defaults to pre 5.0. + /// When using the AutoRegisterTemplate feature, this allows you to overwrite the template in Elasticsearch if it already exists. Defaults to false + /// Specifies the option on how to handle failures when writing the template to Elasticsearch. This is only applicable when using the AutoRegisterTemplate option. + /// Optionally set this value to the name of the index that should be used when the template cannot be written to ES. + /// The default number of shards. + /// The default number of replicas. /// LoggerConfiguration object /// is . public static LoggerConfiguration Elasticsearch( @@ -160,7 +160,7 @@ public static LoggerConfiguration Elasticsearch( int? numberOfReplicas = null) { if (string.IsNullOrEmpty(nodeUris)) - throw new ArgumentNullException("nodeUris", "No Elasticsearch node(s) specified."); + throw new ArgumentNullException(nameof(nodeUris), "No Elasticsearch node(s) specified."); IEnumerable nodes = nodeUris .Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) From 66ea3e826158206c0adcca2039bb8a8624ccc085 Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Sun, 25 Feb 2018 22:33:36 +0100 Subject: [PATCH 4/4] Version bump --- CHANGES.md | 3 +++ GitVersion.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d3fb36e8..922b692c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ == Changelog +6.2 + * Extra overload added to support more settings via AppSettings reader. (#150) + 6.1 * Updated to elasticsearch 6 libraries (#153) * Fix field index option for 6.1+ template to use boolean value. (#148) diff --git a/GitVersion.yml b/GitVersion.yml index d101dc95..25234709 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,4 +1,4 @@ -next-version: 6.0.0 +next-version: 6.2.0 branches: {} ignore: sha: []