Ejemplo n.º 1
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            if (args[0] != null)
            {
                logFile = args[0];
            }
            else
            {
                System.Console.WriteLine("Missing Argument (logfile)");
            }

            // Main processing Thread
            System.Threading.Thread handler = new System.Threading.Thread(new System.Threading.ThreadStart(HandleMessage))
            {
                IsBackground = true
            };
            handler.Start();

            /* Main Loop */
            /* Listen for incoming data on udp port 514 (default for SysLog events) */
            while (queueing || messageQueue.Count != 0)
            {
                try
                {
                    anyIP.Port = 514;

                    // https://www.real-world-systems.com/docs/logger.1.html
                    // sudo apt-get install bsdutils
                    // logger -p auth.notice "Some message for the auth.log file"
                    // logger -p auth.notice "Some message for the auth.log file" --server 127.0.0.1

                    // Receive the message
                    byte[] bytesReceive = udpListener.Receive(ref anyIP);

                    // push the message to the queue, and trigger the queue
                    Data.Message msg = new Data.Message
                    {
                        MessageText = System.Text.Encoding.ASCII.GetString(bytesReceive),
                        RecvTime    = System.DateTime.Now,
                        SourceIP    = anyIP.Address
                    };

                    lock (messageQueue)
                    {
                        messageQueue.Enqueue(msg);
                    }

                    messageTrigger.Set();
                }
                catch (System.Exception ex)
                {
                    // ToDo: Add Error Handling
                    System.Console.WriteLine(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            if (args[0] != null)
            {
                logFile = args[0];
            }
            else
            {
                Console.WriteLine("Missing Argument (logfile)");
            }

            // Main processing Thread
            Thread handler = new Thread(new ThreadStart(HandleMessage))
            {
                IsBackground = true
            };

            handler.Start();

            /* Main Loop */
            /* Listen for incoming data on udp port 514 (default for SysLog events) */
            while (queueing || messageQueue.Count != 0)
            {
                try
                {
                    anyIP.Port = 514;

                    // Receive the message
                    byte[] bytesReceive = udpListener.Receive(ref anyIP);

                    // push the message to the queue, and trigger the queue
                    Data.Message msg = new Data.Message
                    {
                        MessageText = Encoding.ASCII.GetString(bytesReceive),
                        RecvTime    = DateTime.Now,
                        SourceIP    = anyIP.Address
                    };

                    lock (messageQueue)
                    {
                        messageQueue.Enqueue(msg);
                    }

                    messageTrigger.Set();
                }
                catch (Exception)
                {
                    // ToDo: Add Error Handling
                }
            }
        }