A class for sending messages to SumoLogic server.
상속: IDisposable
 /// <summary>
 /// Initializes a new instance of the <see cref="SumoLogicMessageSenderTest"/> class.
 /// </summary>
 public SumoLogicMessageSenderTest()
 {
     this.messagesHandler = new MockHttpMessageHandler();
     this.sumoLogicMessageSender = new SumoLogicMessageSender(this.messagesHandler, null);
     this.sumoLogicMessageSender.Url = new Uri("http://www.fakeadress.com");
     this.sumoLogicMessageSender.RetryInterval = TimeSpan.FromSeconds(30);
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SumoLogicMessageSenderBufferFlushingTask" /> class.
 /// </summary>
 /// <param name="messagesQueue">The queue message for the instance <see cref="BufferWithEviction{TIn}" /> </param>
 /// <param name="messageSender">The http sender.</param>
 /// <param name="maxFlushInterval">The maximum interval for flushing.</param>
 /// <param name="messagesPerRequest">The maximum messages per request.</param>
 /// <param name="messagesName">The messages name.</param>
 /// <param name="log">The log service.</param>
 public SumoLogicMessageSenderBufferFlushingTask(
     BufferWithEviction <string> messagesQueue,
     SumoLogicMessageSender messageSender,
     TimeSpan maxFlushInterval,
     long messagesPerRequest,
     string messagesName,
     ILog log)
     : base(messagesQueue, log)
 {
     this.MaxFlushInterval   = maxFlushInterval;
     this.MessagesPerRequest = messagesPerRequest;
     this.MessagesName       = messagesName;
     this.MessageSender      = messageSender;
 }
 public SumoLogicMessageSenderBufferFlushingTask(
     BufferWithEviction <string> messagesQueue,
     SumoLogicMessageSender messageSender,
     TimeSpan maxFlushInterval,
     long messagesPerRequest,
     string messagesName,
     ILog log)
     : this(messagesQueue,
            messageSender,
            maxFlushInterval,
            messagesPerRequest,
            messagesName,
            null,
            null,
            log)
 {
 }
        /// <summary>
        /// Initialize the target based on the options set
        /// </summary>
        /// <remarks>
        /// This is part of the nLog is called when the Configurations of the LogManager are set.       
        /// If any of the configuration properties are modified then you must set anew the Configuration of the LogManager. 
        /// </remarks>
        protected override void InitializeTarget()
        {
            if (this.UseConsoleLog)
            {
                this.ActivateConsoleLog();
            }

            if (this.LogLog.IsDebugEnabled)
            {
                this.LogLog.Debug("Activating options");
            }

            // Initialize the messages queue
            if (this.messagesQueue == null)
            {
                this.messagesQueue = new BufferWithFifoEviction<string>(this.MaxQueueSizeBytes, new StringLengthCostAssigner(), this.LogLog);
            }
            else
            {
                this.messagesQueue.Capacity = this.MaxQueueSizeBytes;
            }

            // Initialize the sender
            if (this.SumoLogicMessageSender == null)
            {
                this.SumoLogicMessageSender = new SumoLogicMessageSender(this.HttpMessageHandler, this.LogLog);
            }

            this.SumoLogicMessageSender.RetryInterval = TimeSpan.FromMilliseconds(this.RetryInterval);
            this.SumoLogicMessageSender.ConnectionTimeout = TimeSpan.FromMilliseconds(this.ConnectionTimeout);
            this.SumoLogicMessageSender.Url = string.IsNullOrEmpty(this.Url) ? null : new Uri(this.Url);

            // Initialize flusher
            if (this.flushBufferTimer != null)
            {
                this.flushBufferTimer.Stop();
                this.flushBufferTimer.Dispose();
            }

            // Ensure any existing buffer is flushed
            if (this.flushBufferTask != null)
            {
                this.flushBufferTask.FlushAndSend();
            }

            this.flushBufferTask = new SumoLogicMessageSenderBufferFlushingTask(
                this.messagesQueue,
                this.SumoLogicMessageSender,
                TimeSpan.FromMilliseconds(this.MaxFlushInterval),
                this.MessagesPerRequest,
                this.SourceName,
                this.LogLog);

            this.flushBufferTimer = new Timer(TimeSpan.FromMilliseconds(this.FlushingAccuracy).TotalMilliseconds);
            this.flushBufferTimer.Elapsed += (s, e) => this.flushBufferTask.Run();

            this.flushBufferTimer.Start();
        }
        /// <summary>
        /// Is called when the target is closed.
        /// </summary>
        /// /// <remarks>
        /// Releases any resources allocated within the target such as file handles, network connections, etc.        
        /// </remarks>
        protected override void CloseTarget()
        {
            base.CloseTarget();

            if (this.SumoLogicMessageSender != null)
            {
                this.SumoLogicMessageSender.Dispose();
                this.SumoLogicMessageSender = null;
            }

            if (this.flushBufferTimer != null)
            {
                this.flushBufferTimer.Stop();
                this.flushBufferTimer.Dispose();
                this.flushBufferTimer = null;
            }
        }
        /// <summary>
        /// Is called when the appender is closed. Derived classes should override this method if resources need to be released.
        /// </summary>
        /// <remarks>
        /// Releases any resources allocated within the appender such as file handles, network connections, etc.
        /// It is a programming error to append to a closed appender.
        /// </remarks>
        protected override void OnClose()
        {
            base.OnClose();

            if (this.SumoLogicMessageSender != null)
            {
                this.SumoLogicMessageSender.Dispose();
                this.SumoLogicMessageSender = null;
            }
        }
        /// <summary>
        /// Initialize the appender based on the options set
        /// </summary>
        /// <remarks>
        /// This is part of the log4net.Core.IOptionHandler delayed object activation scheme. The ActivateOptions() method must be called
        /// on this object after the configuration properties have been set. Until ActivateOptions() is called this object is in an undefined
        /// state and must not be used. If any of the configuration properties are modified then ActivateOptions() must be called again.
        /// </remarks>
        public override void ActivateOptions()
        {
            if (this.UseConsoleLog)
            {
                this.ActivateConsoleLog();
            }

            if (this.LogLog.IsDebugEnabled)
            {
                this.LogLog.Debug("Activating options");
            }

            // Initialize the sender
            if (this.SumoLogicMessageSender == null)
            {
                this.SumoLogicMessageSender = new SumoLogicMessageSender(this.HttpMessageHandler, this.LogLog);
            }

            this.SumoLogicMessageSender.ConnectionTimeout = TimeSpan.FromMilliseconds(this.ConnectionTimeout);
            this.SumoLogicMessageSender.Url = new Uri(this.Url);
        }