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 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);
            }
        }