Esempio n. 1
0
        public void WhenInvokingCreateMethod_ThenFileWritterCreated()
        {
            LogFileWritter writter = LogFileWritter.Create();

            Assert.IsNotNull(writter);

            writter.Log(LogEvent.Create("error ... ", DateTime.Now));

            Assert.IsTrue(File.Exists(writter.FilePathName()));
            FileInfo fileInfo = new FileInfo(writter.FilePathName());

            Assert.IsTrue(fileInfo.Length > 0);
            writter = null;
        }
Esempio n. 2
0
        public void WhenInvokingLoggerWrite_ThenLogFileBecomeExisted()
        {
            LogFileWritter writter = LogFileWritter.Create();

            new Thread(() =>
            {
                writter.Log(LogEvent.Create("error: ", DateTime.Now));
                writter.Log(LogEvent.Create("warn : ", DateTime.Now));
                writter.Log(LogEvent.Create("info : ", DateTime.Now));
                writter.Log(LogEvent.Create("debug: ", DateTime.Now));
            }).Start();

            Assert.IsTrue(File.Exists(writter.FilePathName()));
            FileInfo fileInfo = new FileInfo(writter.FilePathName());
            long     fileSize = fileInfo.Length;

            Assert.IsTrue(fileSize > 0);
            writter = null;
        }
Esempio n. 3
0
        public void WhenAddManyLogEvent_StartLoggerWorker_HavingListener_QueueCountZero()
        {
            AsynTextLogger textLogger = new AsynTextLogger(
                LogEventQueueDispather.Create().AddEventListener(LogFileWritter.Create())
                );

            textLogger.Start();

            Thread.Sleep(50);

            new Thread(() =>
            {
                for (int i = 0; i < 15; i++)
                {
                    textLogger.Log(LogEvent.Create("error ..." + i, DateTime.Now));
                }
            }).Start();

            Assert.AreEqual(0, textLogger.List().Count);
            textLogger = null;
        }
Esempio n. 4
0
        public void StopWithFlushTest()
        {
            AsynTextLogger textLogger = new AsynTextLogger(
                LogEventQueueDispather.Create().AddEventListener(LogFileWritter.Create())
                );

            textLogger.Start();         //start logger to log
            Thread.Sleep(200);          //simulate to do something in current thread.
            textLogger.StopWithFlush(); //stop logging without flush.

            //meanwhile other threads post log into the dispacher
            new Thread(() =>
            {
                for (int i = 0; i < 1350; i++)
                {
                    textLogger.Log(LogEvent.Create("Test Th1: Number without Flush: " + i.ToString(), DateTime.Now));
                }
                ;
            }).Start();

            new Thread(() =>
            {
                for (int i = 0; i < 1350; i++)
                {
                    textLogger.Log(LogEvent.Create("Test Th2: Number without Flush: " + i.ToString(), DateTime.Now));
                }
                ;
            }).Start();

            new Thread(() =>
            {
                for (int i = 0; i < 1350; i++)
                {
                    textLogger.Log(LogEvent.Create("Test Th3: Number without Flush: " + i.ToString(), DateTime.Now));
                }
                ;
            }).Start();

            new Thread(() =>
            {
                for (int i = 0; i < 1350; i++)
                {
                    textLogger.Log(LogEvent.Create("Test Th4: Number without Flush: " + i.ToString(), DateTime.Now));
                }
                ;
            }).Start();

            new Thread(() =>
            {
                for (int i = 0; i < 1350; i++)
                {
                    textLogger.Log(LogEvent.Create("Test Th5: Number without Flush: " + i.ToString(), DateTime.Now));
                }
                ;
            }).Start();

            new Thread(() =>
            {
                for (int i = 0; i < 1350; i++)
                {
                    textLogger.Log(LogEvent.Create("Test Th6: Number without Flush: " + i.ToString(), DateTime.Now));
                }
                ;
            }).Start();

            //expect having no outstanding logevents in the q.
            Assert.IsTrue(textLogger.List().Count == 0);
            textLogger = null;
        }