/// <summary>
        /// Creates a new instance of the sink
        /// </summary>
        /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
        /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
        /// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
        /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
        /// <param name="formatProvider">The format provider used when rendering the message</param>
        /// <param name="renderTemplate">Whether to render the message template</param>
        /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
        /// <param name="index">The Splunk index to log to</param>
        /// <param name="source">The source of the event</param>
        /// <param name="sourceType">The source type of the event</param>
        /// <param name="host">The host of the event</param>
        /// <param name="messageHandler">The handler used to send HTTP requests</param>
        public EventCollectorSink(
            string splunkHost,
            string eventCollectorToken,
            string uriPath,
            string source,
            string sourceType,
            string host,
            string index,
            int batchIntervalInSeconds,
            int batchSizeLimit,
            IFormatProvider formatProvider    = null,
            bool renderTemplate               = true,
            HttpMessageHandler messageHandler = null)
        {
            _uriPath             = uriPath;
            _splunkHost          = splunkHost;
            _queue               = new ConcurrentQueue <LogEvent>();
            _jsonFormatter       = new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index);
            _batchSizeLimitLimit = batchSizeLimit;

            var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);

            _httpClient = messageHandler != null
                ? new EventCollectorClient(eventCollectorToken, messageHandler)
                : new EventCollectorClient(eventCollectorToken);

            var cancellationToken = new CancellationToken();

            RepeatAction.OnInterval(
                batchInterval,
                async() => await ProcessQueue(),
                cancellationToken);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new instance of the sink
        /// </summary>
        /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
        /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
        /// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
        /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
        /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
        /// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
        /// <param name="messageHandler">The handler used to send HTTP requests</param>
        public EventCollectorSink(
            string splunkHost,
            string eventCollectorToken,
            string uriPath,
            int batchIntervalInSeconds,
            int batchSizeLimit,
            ITextFormatter jsonFormatter,
            HttpMessageHandler messageHandler = null)
        {
            _uriPath             = uriPath;
            _splunkHost          = splunkHost;
            _queue               = new ConcurrentQueue <LogEvent>();
            _jsonFormatter       = jsonFormatter;
            _batchSizeLimitLimit = batchSizeLimit;

            var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);

            _httpClient = messageHandler != null
                ? new EventCollectorClient(eventCollectorToken, messageHandler)
                : new EventCollectorClient(eventCollectorToken);

            var cancellationToken = new CancellationToken();

            RepeatAction.OnInterval(
                batchInterval,
                async() => await ProcessQueue(),
                cancellationToken);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance of the sink
        /// </summary>
        /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
        /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
        /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
        /// <param name="formatProvider">The format provider used when rendering the message</param>
        /// <param name="renderTemplate">Whether to render the message template</param>
        /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
        public EventCollectorSink(
            string splunkHost,
            string eventCollectorToken,
            int batchIntervalInSeconds     = 5,
            int batchSizeLimit             = 100,
            IFormatProvider formatProvider = null,
            bool renderTemplate            = true
            )
        {
            _splunkHost          = splunkHost;
            _eventCollectorToken = eventCollectorToken;
            _queue               = new ConcurrentQueue <LogEvent>();
            _jsonFormatter       = new SplunkJsonFormatter(renderMessage: true, formatProvider: formatProvider, renderTemplate: renderTemplate);
            _batchSizeLimitLimit = batchSizeLimit;

            var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);

            _httpClient = new EventCollectorClient(_eventCollectorToken);

            var cancellationToken = new CancellationToken();

            RepeatAction.OnInterval(
                batchInterval,
                async() => await ProcessQueue(),
                cancellationToken);
        }
        /// <summary>
        /// Creates a new instance of the sink
        /// </summary>
        /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
        /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
        /// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
        /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
        /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
        /// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
        /// <param name="messageHandler">The handler used to send HTTP requests</param>
        public EventCollectorSink(
            string splunkHost,
            string eventCollectorToken,
            string uriPath,
            int batchIntervalInSeconds,
            int batchSizeLimit,
            ITextFormatter jsonFormatter,
            HttpMessageHandler messageHandler = null)
            : base(batchSizeLimit, TimeSpan.FromSeconds(batchIntervalInSeconds))
        {
            _uriPath       = uriPath;
            _splunkHost    = splunkHost;
            _jsonFormatter = jsonFormatter;

            _httpClient = messageHandler != null
                ? new EventCollectorClient(eventCollectorToken, messageHandler)
                : new EventCollectorClient(eventCollectorToken);
        }
        /// <summary>
        /// Creates a new instance of the sink
        /// </summary>
        /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
        /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
        /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
        /// <param name="formatProvider">The format provider used when rendering the message</param>
        /// <param name="renderTemplate">Whether to render the message template</param>
        /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
        public EventCollectorSink(
            string splunkHost,
            string eventCollectorToken,
            int batchIntervalInSeconds = 5,
            int batchSizeLimit = 100,
            IFormatProvider formatProvider = null,
            bool renderTemplate = true
            ) 
        {
            _splunkHost = splunkHost;
            _eventCollectorToken = eventCollectorToken;
            _queue = new ConcurrentQueue<LogEvent>();
            _jsonFormatter = new SplunkJsonFormatter(renderMessage: true, formatProvider: formatProvider, renderTemplate: renderTemplate);
            _batchSizeLimitLimit = batchSizeLimit;
            var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);

            _httpClient = new EventCollectorClient(_eventCollectorToken);

            //TODO: Implement handling similar to the Seq HTTP sink, including dispose flush

            RepeatAction.OnInterval(batchInterval, () => ProcessQueue().Wait(), new CancellationToken());

        }