public void ConsoleLoggerCriticalLogLevelTest() { LogMessage("Testing the Console Logger critical log level."); // Several of these operations are only to ensure they succeed, i.e. do not throw. LogUtils.SetupConsoleLogger(); LogProvider consoleLogProvider = Logger.GetLogProvider(typeof(ConsoleLog)); Assert.IsNotNull(consoleLogProvider); consoleLogProvider.LogLevels = Logger.LogLevels.All; LogMessage("Initialize Console Logger."); consoleLogProvider.InitLog(); LogMessage("Logging text to the Console Logger."); Logger.Critical("This is a trial critical message logged to the Console Logger"); LogMessage("Logging malformed string to the Console Logger."); Action logStringOperation = () => { Logger.Critical("This is a malformed {0} string logged to the Console Logger", null); }; Assert.ThrowsException <ArgumentNullException>(logStringOperation); LogMessage("Deinitializing the Console Logger."); consoleLogProvider.DeinitLog(); }
public void FileLoggerCriticalLogLevelTest() { Log.Comment("Testing the File Logger critical log level."); LogUtils.SetupFileLogger(this.filePath); LogProvider fileLogProvider = Logger.GetLogProvider(typeof(FileLog)); fileLogProvider.LogLevels = Logger.LogLevels.All; Log.Comment("Initialize the File Logger."); VerifyOperation initLog = new VerifyOperation(fileLogProvider.InitLog); Verify.NoThrow(initLog); Log.Comment("Logging text to the File Logger."); string logOutput = "This is a critical message logged to the File Logger"; Logger.Critical(logOutput); // Check if the log file is created. Log.Comment("Verifying the log file creation."); Verify.IsTrue(File.Exists(this.filePath)); fileLogProvider.DeinitLog(); // Check the contents of the file. Log.Comment("Verifying the log file contents."); Verify.IsTrue(File.ReadAllText(this.filePath).Contains(logOutput)); }
public void FileLoggerTest() { LogMessage("Testing the File Logger."); LogUtils.SetupFileLogger(this.filePath); LogProvider fileLogProvider = Logger.GetLogProvider(typeof(FileLog)); fileLogProvider.LogLevels = Logger.LogLevels.All; LogMessage("Initialize the File Logger."); fileLogProvider.InitLog(); LogMessage("Logging text to the File Logger."); string logOutput = "This is an error message logged to the File Logger"; Logger.Error(logOutput); // Check if the log file is created. LogMessage("Verifying the log file creation."); Assert.IsTrue(File.Exists(this.filePath)); fileLogProvider.DeinitLog(); // Check the contents of the file. LogMessage("Verifying the log file contents."); Assert.IsTrue(File.ReadAllText(this.filePath).Contains(logOutput)); }
public void ConsoleLoggerCriticalLogLevelTest() { Log.Comment("Testing the Console Logger critical log level."); // VerfiyOperation makes sure no exceptions are thrown my SetUpConsoleLogger, which // indicates the success of the method call. VerifyOperation setUpConsoleLogger = new VerifyOperation(LogUtils.SetupConsoleLogger); Verify.NoThrow(setUpConsoleLogger); LogProvider consoleLogProvider = Logger.GetLogProvider(typeof(ConsoleLog)); Verify.IsNotNull(consoleLogProvider); consoleLogProvider.LogLevels = Logger.LogLevels.All; Log.Comment("Initialize Console Logger."); VerifyOperation initLog = new VerifyOperation(consoleLogProvider.InitLog); Verify.NoThrow(initLog); Log.Comment("Logging text to the Console Logger."); VerifyOperation logOperation = delegate { Logger.Critical("This is a trial critical message logged to the Console Logger"); }; Verify.NoThrow(logOperation); Log.Comment("Logging malformed string to the Console Logger."); VerifyOperation logStringOperation = delegate { Logger.Critical("This is a malformed {0} string logged to the Console Logger", null); }; Verify.Throws <Exception>(logStringOperation); Log.Comment("Deinitializing the Console Logger."); consoleLogProvider.DeinitLog(); }