Exemple #1
0
        private ElasticsearchSinkState(ElasticsearchSinkOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.IndexFormat))
            {
                throw new ArgumentException("options.IndexFormat");
            }
            if (string.IsNullOrWhiteSpace(options.TypeName))
            {
                throw new ArgumentException("options.TypeName");
            }
            if (string.IsNullOrWhiteSpace(options.TemplateName))
            {
                throw new ArgumentException("options.TemplateName");
            }

            this._templateName        = options.TemplateName;
            this._templateMatchString = IndexFormatRegex.Replace(options.IndexFormat, @"$1*$2");

            _indexDecider = options.IndexDecider ?? ((@event, offset) => string.Format(options.IndexFormat, offset));

            _typeName = options.TypeName;
            _options  = options;

            var configuration = new ConnectionConfiguration(options.ConnectionPool)
                                .SetTimeout(options.ConnectionTimeout)
                                .SetMaximumAsyncConnections(20);

            if (options.ModifyConnectionSetttings != null)
            {
                configuration = options.ModifyConnectionSetttings(configuration);
            }

            _client = new ElasticsearchClient(configuration, connection: options.Connection, serializer: options.Serializer);

            _formatter = options.CustomFormatter ?? new ElasticsearchJsonFormatter(
                formatProvider: options.FormatProvider,
                renderMessage: true,
                closingDelimiter: string.Empty,
                serializer: options.Serializer,
                inlineFields: options.InlineFields
                );
            _durableFormatter = options.CustomDurableFormatter ?? new ElasticsearchJsonFormatter(
                formatProvider: options.FormatProvider,
                renderMessage: true,
                closingDelimiter: Environment.NewLine,
                serializer: options.Serializer,
                inlineFields: options.InlineFields
                );

            this._registerTemplateOnStartup = options.AutoRegisterTemplate;
        }
        private ElasticsearchSinkState(ElasticsearchSinkOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.IndexFormat)) throw new ArgumentException("options.IndexFormat");
            if (string.IsNullOrWhiteSpace(options.TypeName)) throw new ArgumentException("options.TypeName");
            if (string.IsNullOrWhiteSpace(options.TemplateName)) throw new ArgumentException("options.TemplateName");

            this._templateName = options.TemplateName;
            this._templateMatchString = IndexFormatRegex.Replace(options.IndexFormat, @"$1*$2");

            _indexDecider = options.IndexDecider ?? ((@event, offset) => string.Format(options.IndexFormat, offset));

            _typeName = options.TypeName;
            _options = options;

            var configuration = new ConnectionConfiguration(options.ConnectionPool)
                .SetTimeout(options.ConnectionTimeout)
                .SetMaximumAsyncConnections(20);

            if (options.ModifyConnectionSetttings != null)
                configuration = options.ModifyConnectionSetttings(configuration);

            _client = new ElasticsearchClient(configuration, connection: options.Connection, serializer: options.Serializer);

            _formatter = options.CustomFormatter ?? new ElasticsearchJsonFormatter(
                formatProvider: options.FormatProvider,
                renderMessage: true,
                closingDelimiter: string.Empty,
                serializer: options.Serializer,
                inlineFields: options.InlineFields
            );
            _durableFormatter = options.CustomDurableFormatter ?? new ElasticsearchJsonFormatter(
               formatProvider: options.FormatProvider,
               renderMessage: true,
               closingDelimiter: Environment.NewLine,
               serializer: options.Serializer,
               inlineFields: options.InlineFields
               );

            this._registerTemplateOnStartup = options.AutoRegisterTemplate;
        }