protected virtual void SendLogs()
 {
     if (this._config != null)
     {
         while (true)
         {
             var msg = Queue.Take();
             Client.Send(this._config, msg);
         }
     }
 }
Beispiel #2
0
 public void sendBufferedLogsToLoggly(ILogglyAppenderConfig config, bool isBulk)
 {
     if (LogglyStoreLogsInBuffer.arrBufferedMessage.Count > 0)
     {
         int bulkModeBunch  = 100;
         int inputModeBunch = 1;
         int logInBunch     = isBulk ? bulkModeBunch : inputModeBunch;
         arrayMessage = LogglyStoreLogsInBuffer.arrBufferedMessage.Take(logInBunch).ToList();
         message      = isBulk ? String.Join(System.Environment.NewLine, arrayMessage) : arrayMessage[0];
         try
         {
             Client.Send(config, message, isBulk);
             var tempList = LogglyStoreLogsInBuffer.arrBufferedMessage;
             if (LogglyStoreLogsInBuffer.arrBufferedMessage.Count < arrayMessage.Count)
             {
                 LogglyStoreLogsInBuffer.arrBufferedMessage.Clear();
             }
             else
             {
                 tempList.RemoveRange(0, arrayMessage.Count);
             }
             LogglyStoreLogsInBuffer.arrBufferedMessage = tempList;
         }
         catch (WebException e)
         {
             var response = (HttpWebResponse)e.Response;
             if (response != null && response.StatusCode == HttpStatusCode.Forbidden)
             {
                 _logClient.setTokenValid(false);
                 Console.WriteLine("Loggly error: {0}", e.Message);
                 return;
             }
         }
         finally
         {
             arrayMessage.Clear();
             arrayMessage = null;
             GC.Collect();
         }
     }
 }
Beispiel #3
0
        private void DoSend()
        {
            var sendBuffer = new string[_config.BufferSize];

            // WaitAny returns index of completed task or WaitTimeout value (number) in case of timeout.
            // We want to continue unless _stopEvent was set, so unless returned value is 0 - index of _stopEvent
            int flushingHandleIndex = 2;
            var handles             = new WaitHandle[] { _stopEvent, _readyToSendEvent, _flushingEvent };

            int triggeredBy;

            while ((triggeredBy = WaitHandle.WaitAny(handles, _config.SendInterval)) != 0)
            {
                // allow sending partial buffer only when it was triggered by timeout or flush
                if (triggeredBy != WaitHandle.WaitTimeout && triggeredBy != flushingHandleIndex && _messages.Count < sendBuffer.Length)
                {
                    _readyToSendEvent.Reset();
                    continue;
                }

                _sendInProgress = true;
                int sendBufferIndex = 0;
                int bulkSize        = 0;
                while (sendBufferIndex < sendBuffer.Length &&
                       _messages.TryPeek(out var message) &&
                       bulkSize + message.Length <= _config.MaxBulkSizeBytes)
                {
                    bulkSize += message.Length;
                    // peek/dequeue happens only in one thread so what we peeked above is what we dequeue here
                    _messages.TryDequeue(out _);
                    sendBuffer[sendBufferIndex++] = message;
                }

                if (sendBufferIndex > 0)
                {
                    _client.Send(sendBuffer, sendBufferIndex);
                }
                _sendInProgress = false;
            }
        }
Beispiel #4
0
        private void SendLogAction(LoggingEvent loggingEvent)
        {
            //we should always format event in the same thread as
            //many properties used in the event are associated with the current thread
            //like threadname, ndc stacks, threadcontent properties etc.

            //initializing a string for the formatted log
            string _formattedLog = string.Empty;

            //if Layout is null then format the log from the Loggly Client
            if (this.Layout == null)
            {
                Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent);
                _formattedLog = Formatter.ToJson(loggingEvent);
            }
            else
            {
                _formattedLog = Formatter.ToJson(RenderLoggingEvent(loggingEvent), loggingEvent.TimeStamp);
            }

            //sending _formattedLog to the async queue
            ThreadPool.QueueUserWorkItem(x => Client.Send(Config, _formattedLog));
        }
Beispiel #5
0
 protected override void SendBuffer(LoggingEvent[] loggingEvents)
 {
     Client.Send(Config, Formatter.ToJson(loggingEvents));
 }
Beispiel #6
0
 protected override void Append(LoggingEvent loggingEvent)
 {
     Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent);
     Client.Send(Config, Config.InputKey, Config.UserAgent, Config.Tag, Formatter.ToJson(loggingEvent));
 }
Beispiel #7
0
 private void SendLogAction(LoggingEvent loggingEvent)
 {
     Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent);
     Client.Send(Config, Formatter.ToJson(loggingEvent));
 }
Beispiel #8
0
 protected override void SendBuffer(LoggingEvent[] loggingEvents)
 {
     Client.Send(Config, Config.InputKey, Config.UserAgent, Config.Tag, Formatter.ToJson(loggingEvents));
 }