public override void InputThread()
        {
            while (!InputThreadQuitRequested())
            {
                System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(100));

                if (_smtpServer.ReceivedEmailCount > 0)
                {
                    foreach (SmtpMessage message in _smtpServer.ReceivedEmail)
                    {
                        byte[]       bytes = Encoding.UTF8.GetBytes(message.Body);
                        MemoryStream ms    = new MemoryStream(bytes);
                        using (ILogEventParserInstance context = Parser.Begin(ms))
                        {
                            LogEvent logEvent = CreateLogEvent();

                            if (context.ReadNext(logEvent))
                            {
                                foreach (string header in message.Headers.AllKeys)
                                {
                                    logEvent[header] = message.Headers[header];
                                }

                                EventReceived(logEvent);
                            }
                        }
                    }

                    _smtpServer.ClearReceivedEmail();
                }
            }
        }
Пример #2
0
        public override void InputThread()
        {
            try
            {
                using (FileStream stream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (ILogEventParserInstance parserInstance = Parser.Begin(stream))
                    {
                        while (!InputThreadQuitRequested())
                        {
                            long     startingPos  = stream.Position;
                            LogEvent logEventInfo = CreateLogEvent();

                            if (!parserInstance.ReadNext(logEventInfo))
                            {
                                break;
                            }
                            EventReceived(logEventInfo);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #3
0
        public override void InputThread()
        {
            try
            {
                using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
                {
                    socket.Bind(new IPEndPoint(IPAddress.Any, this.Port));
                    logger.Debug("UDP listening on port {0}", this.Port);

                    IPEndPoint sender       = new IPEndPoint(IPAddress.Any, 0);
                    EndPoint   senderRemote = (EndPoint)sender;
                    byte[]     buffer       = new byte[65536];

                    while (!InputThreadQuitRequested())
                    {
                        if (socket.Poll(100000, SelectMode.SelectRead))
                        {
                            int got = socket.ReceiveFrom(buffer, ref senderRemote);
                            if (got > 0)
                            {
                                try
                                {
                                    MemoryStream ms = new MemoryStream(buffer, 0, got);
                                    using (ILogEventParserInstance parserInstance = Parser.Begin(ms))
                                    {
                                        LogEvent logEventInfo = CreateLogEvent();
                                        if (parserInstance.ReadNext(logEventInfo))
                                        {
                                            EventReceived(logEventInfo);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.ToString());
                                }
                                // _listView.Items.Insert(0, System.Text.Encoding.Default.GetString(buffer, 0, got));
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Пример #4
0
 public void InputThread()
 {
     try
     {
         using (_socket)
         {
             NetworkStream ns = new NetworkStream(_socket, FileAccess.Read, false);
             using (ILogEventParserInstance parserInstance = _receiver.Parser.Begin(ns))
             {
                 while (!_receiver.InputThreadQuitRequested())
                 {
                     bool pollResult = _socket.Poll(100000, SelectMode.SelectRead);
                     if (ns.DataAvailable || pollResult)
                     {
                         LogEvent logEvent = _receiver.CreateLogEvent();
                         if (parserInstance.ReadNext(logEvent))
                         {
                             _receiver.EventReceived(logEvent);
                         }
                     }
                 }
             }
         }
     }
     catch (IOException ex)
     {
         logger.Warn("IO Exception: {0}", ex.Message);
     }
     catch (Exception ex)
     {
         _receiver.RaiseError(ex);
     }
     finally
     {
         _receiver.ConnectionClosed(this);
     }
 }