예제 #1
0
        public static LogstashHttpSinkState Create(LogstashHttpSinkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            return(new LogstashHttpSinkState(options));
        }
        /// <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);
            }
        }
예제 #4
0
        private LogstashHttpSinkState(LogstashHttpSinkOptions options)
        {
            Options = options;

            Formatter = options.CustomFormatter ?? new LogstashHttpJsonFormatter(
                formatProvider: options.FormatProvider,
                renderMessage: true,
                closingDelimiter: string.Empty,
                inlineFields: options.InlineFields
                );
            DurableFormatter = options.CustomDurableFormatter ?? new LogstashHttpJsonFormatter(
                formatProvider: options.FormatProvider,
                renderMessage: true,
                closingDelimiter: Environment.NewLine,
                inlineFields: options.InlineFields
                );
        }
예제 #5
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);
 }