public void BufferFull_AutoFlush(string path)
        {
            // Create test directory first
            var logPath = CreateLogsDirectory(path);

            FileLogger fileLogger = null;
            int bufferCountBefore = 0;
            int bufferCountAfter = 0;

            try
            {
                fileLogger = new FileLogger(path, 2, 1000);
                fileLogger.ProcessNotification(Notification.Create("Some message before flushing"));
                fileLogger.ProcessNotification(Notification.Create("Some other message before flushing"));
                bufferCountBefore = fileLogger.BufferCount;
                fileLogger.ProcessNotification(Notification.Create("Some message after flushing!"));
                bufferCountAfter = fileLogger.BufferCount;
            }
            catch (Exception)
            {
                // Ignore any error to make sure the clean up is executed
            }
            finally
            {
                // Clean up directories created
                Thread.Sleep(1000);
                Directory.Delete(path, true);
            }

            // The buffer was reset and the last message was added to it
            Assert.AreEqual(bufferCountBefore, 2);
            Assert.AreEqual(bufferCountAfter, 1);
        }
        public void MaxTimeBetweenFlushes_AutoFlush(string path, int maxTimeBetweenFlushes)
        {
            // Create test directory first
            var logPath = CreateLogsDirectory(path);

            FileLogger fileLogger = null;
            int bufferCountBefore = 0;

            try
            {
                fileLogger = new FileLogger(path, 2, maxTimeBetweenFlushes);
                fileLogger.ProcessNotification(Notification.Create("Some message before flushing"));
                bufferCountBefore = fileLogger.BufferCount;

                Thread.Sleep(maxTimeBetweenFlushes + 20); // adding a small delay to make sure the code is executed
            }
            catch (Exception)
            {
                // Ignore any error to make sure the clean up is executed
            }
            finally
            {
                // Clean up directories created
                Thread.Sleep(1000);
                Directory.Delete(path, true);
            }

            // Check that the buffer was properly flushed
            Assert.AreEqual(bufferCountBefore, 1);
            Assert.That(fileLogger.BufferCount == 0);
        }
        public void ShutDown_Flush(string path)
        {
            // Create test directory first
            CreateLogsDirectory(path);

            int bufferCount = -1;

            try
            {
                var fileLogger = new FileLogger(path, 10, 2000);
                fileLogger.ProcessNotification(Notification.Create("Some message"));
                fileLogger.Shutdown();
                bufferCount = fileLogger.BufferCount;
            }
            catch (Exception)
            {
                // Ignore any error to make sure the clean up is executed
            }
            finally
            {
                // Clean up directories created
                Thread.Sleep(1000);
                Directory.Delete(path, true);
            }

            Assert.That(bufferCount == 0);
        }
        public void FileContentOk(string path, int maxTimeBetweenFlushes)
        {
            // Create test directory first
            var logPath = CreateLogsDirectory(path);
            string logFile = String.Empty;
            string logFileContent = String.Empty;

            try
            {
                var fileLogger = new FileLogger(path, 2, maxTimeBetweenFlushes);
                fileLogger.ProcessNotification(Notification.Create("First message"));
                fileLogger.ProcessNotification(Notification.Create("Second message"));
                fileLogger.ProcessNotification(Notification.Create("this message will be ignored"));
                logFile = fileLogger.FullFilename;
                logFileContent = File.ReadAllText(logFile);
            }
            catch (Exception)
            {
                // Ignore any error to make sure the clean up is executed
            }
            finally
            {
                // Clean up directories created
                Thread.Sleep(1000);
                Directory.Delete(path, true);
            }

            // Check that content is correct
            Assert.AreEqual(logFileContent.CountLines(), 2);
            Assert.That(logFileContent.Contains("First message"));
            Assert.That(logFileContent.Contains("Second message"));
            Assert.That(!logFileContent.Contains("this message will be ignored"));
        }