Example #1
0
        public void TestNetworkLogger()
        {
            const int             eventsToWrite = 1;
            NetworkLoggerListener netListener;

            try
            {
                netListener = new NetworkLoggerListener();
                netListener.Start();
            }
            catch (HttpListenerException)
            {
                Assert.Inconclusive("Could not start HTTP server to validate network logger.");
                return;
            }

            var port = netListener.Port;

            try
            {
                netListener.SetWaitReceivedEventsCount(eventsToWrite);
                LogManager.Start();
                LogManager.DefaultRotate = false;

                var subs   = new[] { new EventProviderSubscription(TestLogger.Write, EventLevel.Verbose), };
                var config = new LogConfiguration("NetLog", LogType.Network, subs)
                {
                    Hostname = IPAddress.Loopback.ToString(),
                    Port     = port
                };
                var logger = LogManager.CreateLogger <NetworkLogger>(config);

                for (int i = 0; i < eventsToWrite; ++i)
                {
                    TestLogger.Write.Int(i);
                    Thread.Sleep(5);
                }

                LogManager.DestroyLogger(logger);
                Assert.IsTrue(netListener.WaitForReceivedEventsCount(5 * 1000));
                Assert.AreEqual(netListener.ReceivedEvents[0].Parameters.Count, 1);

                for (int i = 0; i < eventsToWrite; ++i)
                {
                    Assert.AreEqual(netListener.ReceivedEvents[i].Parameters[0], i);
                }
            }
            finally
            {
                LogManager.Shutdown();
                netListener.Stop();
            }
        }
Example #2
0
        public void TestNetworkLogger()
        {
            const int eventsToWrite = 1;
            const int port          = 9001;
            var       netListener   = new NetworkLoggerListener(port);

            try
            {
                netListener.Start();
                netListener.SetWaitReceivedEventsCount(eventsToWrite);
                LogManager.Start();
                LogManager.SetConfiguration("");
                LogManager.DefaultRotate = false;

                NetworkLogger logger = LogManager.CreateNetworkLogger("NetLog", IPAddress.Loopback.ToString(), port);
                logger.SubscribeToEvents(TestLogger.Write, EventLevel.Verbose);

                for (int i = 0; i < eventsToWrite; ++i)
                {
                    TestLogger.Write.Int(i);
                    Thread.Sleep(5);
                }

                LogManager.DestroyLogger(logger);
                Assert.IsTrue(netListener.WaitForReceivedEventsCount(30 * 1000));
                Assert.AreEqual(netListener.ReceivedEvents[0].Parameters.Count, 1);

                for (int i = 0; i < eventsToWrite; ++i)
                {
                    Assert.AreEqual(netListener.ReceivedEvents[i].Parameters[0], i);
                }
            }
            finally
            {
                LogManager.Shutdown();
                netListener.Stop();
            }
        }
        public void TestNetworkLogger()
        {
            const int eventsToWrite = 1;
            const int port = 9001;
            var netListener = new NetworkLoggerListener(port);

            try
            {
                netListener.Start();
                netListener.SetWaitReceivedEventsCount(eventsToWrite);
                LogManager.Start();
                LogManager.SetConfiguration("");
                LogManager.DefaultRotate = false;

                NetworkLogger logger = LogManager.CreateNetworkLogger("NetLog", IPAddress.Loopback.ToString(), port);
                logger.SubscribeToEvents(TestLogger.Write, EventLevel.Verbose);

                for (int i = 0; i < eventsToWrite; ++i)
                {
                    TestLogger.Write.Int(i);
                    Thread.Sleep(5);
                }

                LogManager.DestroyLogger(logger);
                Assert.IsTrue(netListener.WaitForReceivedEventsCount(30 * 1000));
                Assert.AreEqual(netListener.ReceivedEvents[0].Parameters.Count, 1);

                for (int i = 0; i < eventsToWrite; ++i)
                {
                    Assert.AreEqual(netListener.ReceivedEvents[i].Parameters[0], i);
                }
            }
            finally
            {
                LogManager.Shutdown();
                netListener.Stop();
            }
        }