Esempio n. 1
0
        public void Logger_WhenUsingFile_ThenWritesOutputToFile()
        {
            var logger = new FileLogger {LogLevel = LogLevel.Information};
            logger.Log("test", LogLevel.Information);
            logger.Close();

            Assert.IsTrue(File.Exists(logger.FullPathName));

            logger.TryDeleteFile();
        }
Esempio n. 2
0
        public void Logger_WhenUsingFile_ThenRollingFilesShouldIncrement()
        {
            // create first rolling log file
            var logger1 = new FileLogger {LogLevel = LogLevel.Verbose};
            logger1.Log("test");
            Assert.IsTrue(File.Exists(logger1.FullPathName));
            logger1.Close();

            // create a new file logger (effectively a new logging session)
            // and create the second rolling log file
            var logger2 = new FileLogger {LogLevel = LogLevel.Verbose};
            logger2.Log("test");
            Assert.IsTrue(File.Exists(logger2.FullPathName));
            logger2.Close();

            // get the number values from each file
            // used the default file name template, so the format is
            // "logfile###.log"
            var logNumber1 = int.Parse(logger1.CurrentLogFileName.Substring(7, 3));
            var logNumber2 = int.Parse(logger2.CurrentLogFileName.Substring(7, 3));

            Assert.IsTrue(logNumber2 == logNumber1 + 1);

            // clean up
            logger1.TryDeleteFile();
            logger2.TryDeleteFile();
        }