21
21
using Serilog . Events ;
22
22
using Serilog . Sinks . Elasticsearch ;
23
23
using System . Collections . Specialized ;
24
+ using System . ComponentModel ;
24
25
25
26
namespace Serilog
26
27
{
@@ -62,6 +63,45 @@ public static LoggerConfiguration Elasticsearch(
62
63
) ;
63
64
}
64
65
66
+ /// <summary>
67
+ /// Overload to allow basic configuration through AppSettings.
68
+ /// </summary>
69
+ /// <param name="loggerSinkConfiguration">Options for the sink.</param>
70
+ /// <param name="nodeUris">A comma or semi column separated list of URIs for Elasticsearch nodes.</param>
71
+ /// <param name="indexFormat"><see cref="ElasticsearchSinkOptions.IndexFormat"/></param>
72
+ /// <param name="templateName"><see cref="ElasticsearchSinkOptions.TemplateName"/></param>
73
+ /// <param name="typeName"><see cref="ElasticsearchSinkOptions.TypeName"/></param>
74
+ /// <param name="batchPostingLimit"><see cref="ElasticsearchSinkOptions.BatchPostingLimit"/></param>
75
+ /// <param name="period"><see cref="ElasticsearchSinkOptions.Period"/></param>
76
+ /// <param name="inlineFields"><see cref="ElasticsearchSinkOptions.InlineFields"/></param>
77
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
78
+ /// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
79
+ /// <param name="bufferBaseFilename"><see cref="ElasticsearchSinkOptions.BufferBaseFilename"/></param>
80
+ /// <param name="bufferFileSizeLimitBytes"><see cref="ElasticsearchSinkOptions.BufferFileSizeLimitBytes"/></param>
81
+ /// <param name="bufferLogShippingInterval"><see cref="ElasticsearchSinkOptions.BufferLogShippingInterval"/></param>
82
+ /// <param name="connectionGlobalHeaders">A comma or semi column separated list of key value pairs of headers to be added to each elastic http request</param>
83
+ [ Obsolete ( "New code should not be compiled against this obsolete overload" ) , EditorBrowsable ( EditorBrowsableState . Never ) ]
84
+ public static LoggerConfiguration Elasticsearch (
85
+ this LoggerSinkConfiguration loggerSinkConfiguration ,
86
+ string nodeUris ,
87
+ string indexFormat ,
88
+ string templateName ,
89
+ string typeName ,
90
+ int batchPostingLimit ,
91
+ int period ,
92
+ bool inlineFields ,
93
+ LogEventLevel restrictedToMinimumLevel ,
94
+ string bufferBaseFilename ,
95
+ long ? bufferFileSizeLimitBytes ,
96
+ long bufferLogShippingInterval ,
97
+ string connectionGlobalHeaders ,
98
+ LoggingLevelSwitch levelSwitch )
99
+ {
100
+ return Elasticsearch ( loggerSinkConfiguration , nodeUris , indexFormat , templateName , typeName , batchPostingLimit , period , inlineFields , restrictedToMinimumLevel , bufferBaseFilename ,
101
+ bufferFileSizeLimitBytes , bufferLogShippingInterval , connectionGlobalHeaders , levelSwitch , 5 , EmitEventFailureHandling . WriteToSelfLog , 100000 , null , false ,
102
+ AutoRegisterTemplateVersion . ESv2 , false , RegisterTemplateRecovery . IndexAnyway , null , null , null ) ;
103
+ }
104
+
65
105
/// <summary>
66
106
/// Overload to allow basic configuration through AppSettings.
67
107
/// </summary>
@@ -79,9 +119,15 @@ public static LoggerConfiguration Elasticsearch(
79
119
/// <param name="bufferFileSizeLimitBytes"><see cref="ElasticsearchSinkOptions.BufferFileSizeLimitBytes"/></param>
80
120
/// <param name="bufferLogShippingInterval"><see cref="ElasticsearchSinkOptions.BufferLogShippingInterval"/></param>
81
121
/// <param name="connectionGlobalHeaders">A comma or semi column separated list of key value pairs of headers to be added to each elastic http request</param>
122
+ /// <param name="connectionTimeout"><see cref="ElasticsearchSinkOptions.ConnectionTimeout"/></param>
123
+ /// <param name="emitEventFailure"><see cref="ElasticsearchSinkOptions.EmitEventFailure"/></param>
124
+ /// <param name="queueSizeLimit"><see cref="ElasticsearchSinkOptions.QueueSizeLimit"/></param>
125
+ /// <param name="pipelineName"><see cref="ElasticsearchSinkOptions.PipelineName"/></param>
82
126
/// <param name="autoRegisterTemplate"><see cref="ElasticsearchSinkOptions.AutoRegisterTemplate"/></param>
83
- /// <param name="autoRegisterTemplateVersion"><see cref="ElasticsearchSinkOptions.AutoRegisterTemplateVersion"/></param>
127
+ /// <param name="autoRegisterTemplateVersion"><see cref="ElasticsearchSinkOptions.AutoRegisterTemplateVersion"/></param>
84
128
/// <param name="overwriteTemplate"><see cref="ElasticsearchSinkOptions.OverwriteTemplate"/></param>
129
+ /// <param name="registerTemplateFailure"><see cref="ElasticsearchSinkOptions.RegisterTemplateFailure"/></param>
130
+ /// <param name="deadLetterIndexName"><see cref="ElasticsearchSinkOptions.DeadLetterIndexName"/></param>
85
131
/// <param name="numberOfShards"><see cref="ElasticsearchSinkOptions.NumberOfShards"/></param>
86
132
/// <param name="numberOfReplicas"><see cref="ElasticsearchSinkOptions.NumberOfReplicas"/></param>
87
133
/// <returns>LoggerConfiguration object</returns>
@@ -101,9 +147,15 @@ public static LoggerConfiguration Elasticsearch(
101
147
long bufferLogShippingInterval = 5000 ,
102
148
string connectionGlobalHeaders = null ,
103
149
LoggingLevelSwitch levelSwitch = null ,
150
+ int connectionTimeout = 5 ,
151
+ EmitEventFailureHandling emitEventFailure = EmitEventFailureHandling . WriteToSelfLog ,
152
+ int queueSizeLimit = 100000 ,
153
+ string pipelineName = null ,
104
154
bool autoRegisterTemplate = false ,
105
155
AutoRegisterTemplateVersion autoRegisterTemplateVersion = AutoRegisterTemplateVersion . ESv2 ,
106
156
bool overwriteTemplate = false ,
157
+ RegisterTemplateRecovery registerTemplateFailure = RegisterTemplateRecovery . IndexAnyway ,
158
+ string deadLetterIndexName = null ,
107
159
int ? numberOfShards = null ,
108
160
int ? numberOfReplicas = null )
109
161
{
@@ -166,12 +218,23 @@ public static LoggerConfiguration Elasticsearch(
166
218
options . ModifyConnectionSettings = ( c ) => c . GlobalHeaders ( headers ) ;
167
219
}
168
220
221
+ options . ConnectionTimeout = TimeSpan . FromSeconds ( connectionTimeout ) ;
222
+ options . EmitEventFailure = emitEventFailure ;
223
+ options . QueueSizeLimit = queueSizeLimit ;
224
+ options . PipelineName = pipelineName ;
225
+
169
226
options . AutoRegisterTemplate = autoRegisterTemplate ;
170
227
options . AutoRegisterTemplateVersion = autoRegisterTemplateVersion ;
228
+ options . RegisterTemplateFailure = registerTemplateFailure ;
171
229
options . OverwriteTemplate = overwriteTemplate ;
172
230
options . NumberOfShards = numberOfShards ;
173
231
options . NumberOfReplicas = numberOfReplicas ;
174
232
233
+ if ( ! string . IsNullOrWhiteSpace ( deadLetterIndexName ) )
234
+ {
235
+ options . DeadLetterIndexName = deadLetterIndexName ;
236
+ }
237
+
175
238
return Elasticsearch ( loggerSinkConfiguration , options ) ;
176
239
}
177
240
}
0 commit comments