/// <summary>
        /// Initializes a new instance of the <see cref="SumoLogicSink"/> class.
        /// </summary>
        /// <param name="log">The log service.</param>
        /// <param name="httpMessageHandler">HTTP message handler.</param>
        /// <param name="connection">Connection configuration.</param>
        /// <param name="source">Event source describer.</param>
        /// <param name="formatter">Text formatter.</param>
        public SumoLogicSink(
            ILog log,
            HttpMessageHandler httpMessageHandler,
            SumoLogicConnection connection,
            SumoLogicSource source,
            ITextFormatter formatter)
        {
            if (connection is null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            this.source    = source ?? throw new ArgumentNullException(nameof(source));
            this.formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));

            this.logService = log ?? new DummyLog();

            this.messageSender = new SumoLogicMessageSender(httpMessageHandler, this.logService)
            {
                Url               = connection.Uri,
                ClientName        = connection.ClientName,
                ConnectionTimeout = connection.ConnectionTimeout,
                RetryInterval     = connection.RetryInterval,
            };
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SumoLogicSink"/> class.
        /// </summary>
        /// <param name="log">The log service.</param>
        /// <param name="httpMessageHandler">HTTP message handler.</param>
        /// <param name="connection">Connection configuration.</param>
        /// <param name="source">Event source describer.</param>
        /// <param name="formatter">Text formatter.</param>
        public SumoLogicSink(
            ILog log,
            HttpMessageHandler httpMessageHandler,
            SumoLogicConnection connection,
            SumoLogicSource source,
            ITextFormatter formatter)
        {
            if (connection is null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
            _log       = log ?? new DummyLog();

            _messageSender = MessageSenderFactory.CreateMessageSender(_log, httpMessageHandler, connection);
            _messageQueue  = MessageQueueFactory.CreateMessageQueue(_log, connection);
            SumoLogicMessageSenderBufferFlushingTask flushBufferTask = FlushBufferTaskFactory.CreateFlushBufferTask(
                _log,
                _messageSender,
                _messageQueue,
                connection,
                source);

            _flushBufferTimer = new Timer(
                _ => flushBufferTask.Run(),
                null,
                TimeSpan.FromMilliseconds(0),
                connection.FlushingAccuracy);
        }
예제 #3
0
 public static SumoLogicMessageSender CreateMessageSender(
     ILog log,
     HttpMessageHandler messageHandler,
     SumoLogicConnection connection) =>
 new SumoLogicMessageSender(messageHandler, log)
 {
     Url               = connection.Uri,
     ClientName        = connection.ClientName,
     ConnectionTimeout = connection.ConnectionTimeout,
     RetryInterval     = connection.RetryInterval,
 };
        public static SumoLogicConnection SetTimeSpanIfNotEmpty(
            this SumoLogicConnection target,
            Expression <Func <SumoLogicConnection, TimeSpan> > member,
            long?value)
        {
            if (value.HasValue &&
                member.Body is MemberExpression memberExpression &&
                memberExpression.Member is PropertyInfo propertyInfo)
            {
                propertyInfo.SetValue(target, TimeSpan.FromMilliseconds(value.Value), null);
            }

            return(target);
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BufferedSumoLogicSink"/> class.
        /// </summary>
        /// <param name="log">The log service.</param>
        /// <param name="httpMessageHandler">HTTP message handler.</param>
        /// <param name="connection">Connection configuration.</param>
        /// <param name="source">Event source describer.</param>
        /// <param name="formatter">Text formatter.</param>
        public BufferedSumoLogicSink(
            ILog log,
            HttpMessageHandler httpMessageHandler,
            SumoLogicConnection connection,
            SumoLogicSource source,
            ITextFormatter formatter)
        {
            if (connection is null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            this.formatter  = formatter ?? throw new ArgumentNullException(nameof(formatter));
            this.logService = log ?? new DummyLog();

            this.messageSender = new SumoLogicMessageSender(httpMessageHandler, this.logService)
            {
                Url               = connection.Uri,
                ClientName        = connection.ClientName,
                ConnectionTimeout = connection.ConnectionTimeout,
                RetryInterval     = connection.RetryInterval,
            };

            this.messageQueue = new BufferWithFifoEviction <string>(
                connection.MaxQueueSizeBytes,
                new StringLengthCostAssigner(),
                this.logService);

            this.flushBufferTask = new SumoLogicMessageSenderBufferFlushingTask(
                this.messageQueue,
                this.messageSender,
                connection.MaxFlushInterval,
                connection.MessagesPerRequest,
                source.SourceName,
                source.SourceCategory,
                source.SourceHost,
                this.logService);

            this.flushBufferTimer = new Timer(
                _ => flushBufferTask.Run(), // No task await to avoid unhandled exception
                null,
                TimeSpan.FromMilliseconds(0),
                connection.FlushingAccuracy);
        }
 public static SumoLogicMessageSenderBufferFlushingTask CreateFlushBufferTask(
     ILog log,
     SumoLogicMessageSender messageSender,
     BufferWithEviction <string> messageQueue,
     SumoLogicConnection connection,
     SumoLogicSource source) =>
 new SumoLogicMessageSenderBufferFlushingTask(
     messageQueue,
     messageSender,
     connection.MaxFlushInterval,
     connection.MessagesPerRequest,
     source.SourceName,
     source.SourceCategory,
     source.SourceHost,
     log);
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SumoLogicUnbufferedSink"/> class.
        /// </summary>
        /// <param name="log">The log service.</param>
        /// <param name="httpMessageHandler">HTTP message handler.</param>
        /// <param name="connection">Connection configuration.</param>
        /// <param name="source">Event source describer.</param>
        /// <param name="formatter">Text formatter.</param>
        public SumoLogicUnbufferedSink(
            ILog log,
            HttpMessageHandler httpMessageHandler,
            SumoLogicConnection connection,
            SumoLogicSource source,
            ITextFormatter formatter)
        {
            if (connection is null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            _source    = source ?? throw new ArgumentNullException(nameof(source));
            _formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));

            _log           = log ?? new DummyLog();
            _messageSender = MessageSenderFactory.CreateMessageSender(_log, httpMessageHandler, connection);
        }
 public static BufferWithFifoEviction <string> CreateMessageQueue(ILog log, SumoLogicConnection connection) =>
 new BufferWithFifoEviction <string>(
     connection.MaxQueueSizeBytes,
     new StringLengthCostAssigner(),
     log);