Exemplo n.º 1
0
        public void verify_logs_with_null_data()
        {
            // Prepare listener to receive messages
            var opts = new Ext.UdpLoggerOptions();

            using (_receiver = new UdpReceiver())
            {
                _receiver.Start(opts);

                // Add options to provider before create logger
                _provider = new Ext.UdpLoggerProvider(opts);
                var logger = _provider.CreateLogger("test") as Ext.UdpLogger;

                // Log non-null data
                logger.Log(GetRandomLogLevel(), DEFAULT_EVENTID, DEFAULT_STATE, DEFAULT_EXCEPTION, setStringFormatter);

                // log null data
                logger.Log(GetRandomLogLevel(), DEFAULT_EVENTID, NULL_STATE, DEFAULT_EXCEPTION, setStringFormatter);
                logger.Log(GetRandomLogLevel(), DEFAULT_EVENTID, DEFAULT_STATE, NULL_EXCEPTION, setStringFormatter);

                // Log non-null data
                logger.Log(GetRandomLogLevel(), DEFAULT_EVENTID, DEFAULT_STATE, DEFAULT_EXCEPTION, setStringFormatter);

                // Brief wait & stop listener
                System.Threading.Thread.Sleep(100);
                _receiver.Stop();

                // NOTE: RetrieveMessages returns a _consuming_ enumerator, so it can only be used once.
                _receiver.RetrieveMessages().Count().Should().Be(4);  // -1 since None shouldn't be logged
            }
        }
Exemplo n.º 2
0
        public void verify_each_loglevel()
        {
            // Prepare listener to receive messages
            var opts = new Ext.UdpLoggerOptions();

            using (_receiver = new UdpReceiver())
            {
                _receiver.Start(opts);

                // Add options to provider before create logger
                _provider = new Ext.UdpLoggerProvider(opts);
                var logger = _provider.CreateLogger("test") as Ext.UdpLogger;

                foreach (int level in _logLevels)
                {
                    // Log some messages
                    logger.Log((LogLevel)level, DEFAULT_EVENTID, DEFAULT_STATE, DEFAULT_EXCEPTION, setStringFormatter);
                }

                // Brief wait & stop listener
                System.Threading.Thread.Sleep(100);
                _receiver.Stop();

                // NOTE: RetrieveMessages returns a _consuming_ enumerator, so it can only be used once.
                _receiver.RetrieveMessages().Count().Should().Be(_logLevels.Length - 1);  // -1 since None shouldn't be logged
            }
        }
Exemplo n.º 3
0
 public UdpLoggerProvider(UdpLoggerOptions options)
 {
     if (null == options)
     {
         throw new ArgumentNullException(nameof(options));
     }
     Options = options;
 }
        public UdpLoggerProcessor(UdpLoggerOptions options)
        {
            if (null == options)
            {
                throw new ArgumentNullException(nameof(options));
            }
            _options = options;

            _udpSender = new UdpClient(); //options.IPEndPoint);

            // Start message queue processor
            _shutdown     = false;
            _outputThread = new Thread(ProcessLogQueue)
            {
                IsBackground = true,
                Name         = "Udp logger queue processing thread"
            };
            _outputThread.Start();
        }
        public void Start(Ext.UdpLoggerOptions options)
        {
            _stopListener = false;

            _client = new UdpClient(options.IPEndPoint);

            var senderIP = new IPEndPoint(0, 0);

            // Spawn Udp receiver
            System.Threading.Tasks.Task.Run(() => {
                while (!_stopListener)
                {
                    var r = _client.ReceiveAsync().Result;

                    if (r.Buffer.Length > 0)
                    {
                        string msg = System.Text.Encoding.ASCII.GetString(r.Buffer);
                        _messageQueue.Add(msg);
                    }
                }
            });
        }
Exemplo n.º 6
0
        public void verify_few_log_messages()
        {
            // Prepare listener to receive messages
            var opts = new Ext.UdpLoggerOptions();

            testLog.WriteLine($"UDP options: {opts.IPEndPoint.ToString()}");

            using (_receiver = new UdpReceiver())
            {
                _receiver.Start(opts);

                // Add options to provider before create logger
                _provider = new Ext.UdpLoggerProvider(opts);
                var logger = _provider.CreateLogger("test") as Ext.UdpLogger;

                // Log some messages
                logger.Log(LogLevel.Debug, DEFAULT_EVENTID, DEFAULT_STATE, DEFAULT_EXCEPTION, setStringFormatter);
                logger.Log(LogLevel.Debug, DEFAULT_EVENTID, NULL_STATE, DEFAULT_EXCEPTION, setStringFormatter);
                logger.Log(LogLevel.Debug, DEFAULT_EVENTID, DEFAULT_STATE, NULL_EXCEPTION, setStringFormatter);
                // LogLevel None results is no log
                logger.Log(LogLevel.None, DEFAULT_EVENTID, DEFAULT_STATE, NULL_EXCEPTION, setStringFormatter);

                // Brief wait & stop listener
                System.Threading.Thread.Sleep(100);
                _receiver.Stop();


                // NOTE: RetrieveMessages returns a _consuming_ enumerator, so it can only be used once.
                int msgCount = 0;
                foreach (var msg in _receiver.RetrieveMessages())
                {
                    ++msgCount;
                }
                msgCount.Should().Be(3);
            }
        }