Esempio n. 1
0
        private void Start()
        {
            while (_udpClient != null && _remoteEndPoint != null)
            {
                try
                {
                    var buffer       = _udpClient.Receive(ref _remoteEndPoint);
                    var loggingEvent = Encoding.UTF8.GetString(buffer);

                    if (Notifiable == null)
                    {
                        continue;
                    }

                    var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger");
                    logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-");
                    logMsg.LoggerName     = $"{_remoteEndPoint.Address.ToString().Replace(".", "-")}_{logMsg.LoggerName}";
                    Notifiable.Notify(logMsg);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return;
                }
            }
        }
Esempio n. 2
0
        void Start(object newSocket)
        {
            try
            {
                using (var socket = (Socket)newSocket)
                    using (var ns = new NetworkStream(socket, FileAccess.Read, false))
                        while (_socket != null)
                        {
                            var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(ns, "TcpLogger");
                            logMsg.RootLoggerName = logMsg.LoggerName;
                            logMsg.LoggerName     = string.Format(":{1}.{0}", logMsg.LoggerName, _port);

                            if (Notifiable != null)
                            {
                                Notifiable.Notify(logMsg);
                            }
                        }
            }
            catch (IOException)
            {
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 3
0
        private void Start()
        {
            while ((_udpClient != null) && (_remoteEndPoint != null))
            {
                try
                {
                    byte[] buffer       = _udpClient.Receive(ref _remoteEndPoint);
                    string loggingEvent = Encoding.UTF8.GetString(buffer);

                    //Console.WriteLine(loggingEvent);
                    //  Console.WriteLine("Count: " + count++);

                    if (Notifiable == null)
                    {
                        continue;
                    }

                    LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger");
                    logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-");
                    logMsg.LoggerName     = string.Format("{0}_{1}", _remoteEndPoint.Address.ToString().Replace(".", "-"), logMsg.LoggerName);
                    Notifiable.Notify(logMsg);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return;
                }
            }
        }
Esempio n. 4
0
        private void AddReceiver(Type type)
        {
            var info = new ReceiverInfo {
                Name = ReceiverUtils.GetTypeDescription(type), Type = type
            };

            _receiverTypes.Add(type.FullName, info);
        }
        private void AddReceiver(Type type)
        {
            var info = new ReceiverInfo {
                Name = ReceiverUtils.GetTypeDescription(type), Type = type
            };

            ReceiverTypes.Add(type.FullName ?? throw new InvalidOperationException(), info);
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        private void Start()
        {
            _queue = new MessageQueue(QueueName);

            _queue.ReceiveCompleted += delegate(Object source, ReceiveCompletedEventArgs asyncResult)
            {
                try
                {
                    // End the asynchronous receive operation.
                    Message m = ((MessageQueue)source).EndReceive(asyncResult.AsyncResult);

                    if (Notifiable != null)
                    {
                        string     loggingEvent = Encoding.ASCII.GetString(((MemoryStream)m.BodyStream).ToArray());
                        LogMessage logMsg       = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger");
                        logMsg.LoggerName     = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName);
                        logMsg.RootLoggerName = QueueName;
                        Notifiable.Notify(logMsg);
                    }


                    if (BulkProcessBackedUpMessages)
                    {
                        Message[] all = ((MessageQueue)source).GetAllMessages();
                        if (all.Length > 0)
                        {
                            int numberofmessages = all.Length > 1000 ? 1000 : all.Length;

                            LogMessage[] logs = new LogMessage[numberofmessages];

                            for (int i = 0; i < numberofmessages; i++)
                            {
                                Message thisone = ((MessageQueue)source).Receive();

                                string loggingEvent =
                                    Encoding.ASCII.GetString(((MemoryStream)thisone.BodyStream).ToArray());
                                LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger");
                                logMsg.LoggerName = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName);
                                logs[i]           = logMsg;
                            }

                            Notifiable.Notify(logs);
                        }
                    }

                    ((MessageQueue)source).BeginReceive();
                }
                catch (MessageQueueException)
                {
                    // Handle sources of MessageQueueException.
                }
            };

            _queue.BeginReceive();
        }
Esempio n. 7
0
        private void NotifyWebSocketStateChange(WebSocketState state)
        {
            var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent($"WebSocket state changed: {state}", "wssLogger");

            logMsg.Level = LogLevels.Instance[LogLevel.Info];

            var loggerName = WebSocketServerUri.Replace("wss://", "wss-").Replace(":", "-").Replace(".", "-");

            logMsg.RootLoggerName = loggerName;
            logMsg.LoggerName     = $"{loggerName}_{logMsg.LoggerName}";
            Notifiable.Notify(logMsg);
        }
Esempio n. 8
0
        private void ReadFile()
        {
            if ((_fileReader == null) || (_fileReader.BaseStream.Length == _lastFileLength))
            {
                return;
            }

            // Seek to the last file length
            _fileReader.BaseStream.Seek(_lastFileLength, SeekOrigin.Begin);

            // Get last added lines
            string            line;
            var               sb      = new StringBuilder();
            List <LogMessage> logMsgs = new List <LogMessage>();

            while ((line = _fileReader.ReadLine()) != null)
            {
                if (_fileFormat == FileFormatEnums.Flat)
                {
                    LogMessage logMsg = new LogMessage();
                    logMsg.RootLoggerName = _loggerName;
                    logMsg.LoggerName     = _fullLoggerName;
                    logMsg.ThreadName     = "NA";
                    logMsg.Message        = line;
                    logMsg.TimeStamp      = DateTime.Now;
                    logMsg.Level          = LogLevels.Instance[LogLevel.Info];

                    logMsgs.Add(logMsg);
                }
                else
                {
                    sb.Append(line);

                    // This condition allows us to process events that spread over multiple lines
                    if (line.Contains("</log4j:event>"))
                    {
                        LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(sb.ToString(), _fullLoggerName);
                        logMsgs.Add(logMsg);
                        sb = new StringBuilder();
                    }
                }
            }

            // Notify the UI with the set of messages
            Notifiable.Notify(logMsgs.ToArray());

            // Update the last file length
            _lastFileLength = _fileReader.BaseStream.Position;
        }
Esempio n. 9
0
        private void OnBufferReceived(Task <WebSocketReceiveResult> obj)
        {
            if (obj.IsCompleted)
            {
                var loggingEvent = Encoding.UTF8.GetString(_buffer);
                _messageBuilder.Append(loggingEvent);

                Console.WriteLine(loggingEvent);

                if (obj.Result.EndOfMessage)
                {
                    var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "wssLogger");
                    logMsg.Level = LogLevels.Instance[LogLevel.Debug];

                    var loggerName = WebSocketServerUri.Replace("wss://", "wss-").Replace(":", "-").Replace(".", "-");
                    logMsg.RootLoggerName = loggerName;
                    logMsg.LoggerName     = $"{loggerName}_{logMsg.LoggerName}";
                    Notifiable.Notify(logMsg);

                    _messageBuilder.Clear();
                }
            }
        }