public void DatabaseErrorLog() { JobLogger.LogToDatabase(); JobLogger.EnableMessageLog(); var message = "Test error"; var statement = "[" + LogType.Error.ToString() + "] : " + message; JobLogger.LogMessage(message, LogType.Error); SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); connection.Open(); SqlCommand command = new SqlCommand("SELECT LogDescription FROM dbo.Log ORDER BY Id DESC LIMIT 1;"); var lastRecord = ""; using (var reader = command.ExecuteReader()) { while (reader.Read()) { lastRecord = reader[0].ToString(); } } Assert.AreEqual(statement, lastRecord); }
public void ConsoleMessageLogIsWhite() { JobLogger.LogToConsole(); JobLogger.EnableMessageLog(); var message = "Log message"; JobLogger.LogMessage(message, LogType.Message); Assert.AreEqual(Console.ForegroundColor, ConsoleColor.White); }
public void IfErrorNotEnableConsoleColorIsNotAffected() { JobLogger.LogToConsole(); JobLogger.EnableWarningLog(); JobLogger.EnableMessageLog(); var message = "Log to console"; Console.ForegroundColor = ConsoleColor.Black; JobLogger.LogMessage(message, LogType.Error); Assert.AreEqual(Console.ForegroundColor, ConsoleColor.Red); }
public void FileErrorLog() { JobLogger.LogToFile(); JobLogger.EnableMessageLog(); var message = "Test error"; var messageFile = DateTime.Now.ToShortDateString() + " [" + LogType.Error.ToString() + "] : " + message; JobLogger.LogMessage(message, LogType.Error); var file = ConfigurationManager.AppSettings["LogFileDirectory"] + "LogFile " + DateTime.Now.ToShortDateString().Replace("/", "_") + ".txt"; var lines = File.ReadAllLines(file); var lastLine = lines[lines.Length - 1]; Assert.AreEqual(messageFile, lastLine); }