/// <summary>
        /// Initializes a new instance of the <see cref="LogstashHttpSink"/> class with the provided options
        /// </summary>
        /// <param name="options">
        /// Options configuring how the sink behaves, may NOT be null
        /// </param>
        public LogstashHttpSink(LogstashHttpSinkOptions options)
            : base(options.BatchPostingLimit, options.Period)
        {
            _state = LogstashHttpSinkState.Create(options);
            if (options.UserName?.Length > 0 && options.UserPassword?.Length > 0)
            {
                string base64 = Base64Encode($"{_state.Options.UserName}:{_state.Options.UserPassword}");
                authorizationHeader = $"Basic {base64}";

                HttpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LogstashHttpSink"/> class with the provided options
        /// </summary>
        /// <param name="options">
        /// Options configuring how the sink behaves, may NOT be null
        /// </param>
        public LogstashHttpSink(LogstashHttpSinkOptions options)
            : base(options.BatchPostingLimit, options.Period)
        {
            _state = LogstashHttpSinkState.Create(options);

            // Set basic authentication header for provided user and password
            if (!string.IsNullOrWhiteSpace(options.LogstashUser) &&
                !string.IsNullOrWhiteSpace(options.LogstashPassword))
            {
                var headerKey   = "Basic";
                var headerValue = Convert.ToBase64String(
                    Encoding.ASCII.GetBytes(
                        $"{options.LogstashUser}:{options.LogstashPassword}"));

                HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(headerKey, headerValue);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogstashHttpSink"/> class with the provided options
 /// </summary>
 /// <param name="options">
 /// Options configuring how the sink behaves, may NOT be null
 /// </param>
 public LogstashHttpSink(LogstashHttpSinkOptions options)
     : base(options.BatchPostingLimit, options.Period)
 {
     _state = LogstashHttpSinkState.Create(options);
 }