public bool LogMessage(string message, LogType logType, MessageTypeToLog messageTypeToLog) { bool value = true; int typeMessage = (int)logType; string conexion = ConfigurationManager.AppSettings["ConnectionString"]; using (SqlConnection connection = new SqlConnection(conexion)) { string sqlQuery = string.Format("Insert into Log Values('{0}', {1})", message, typeMessage.ToString()); connection.Open(); using (SqlCommand command = new SqlCommand(sqlQuery)) { try { command.ExecuteNonQuery(); } catch (Exception) { conexion.Clone(); value = false; } } } return value; }
public bool LogMessage(string message, LogType logType, MessageTypeToLog messageTypeToLog) { try { switch (logType) { case LogType.none: break; case LogType.Message: if (messageTypeToLog.Message) Console.ForegroundColor = ConsoleColor.White; break; case LogType.Error: if (messageTypeToLog.Error) Console.ForegroundColor = ConsoleColor.Red; break; case LogType.Warning: if (messageTypeToLog.Warning) Console.ForegroundColor = ConsoleColor.Yellow; break; default: break; } Console.WriteLine(DateTime.Now.ToShortDateString() + message); return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } }
public void JobLogger_LogMessage_ToDataBase_Warning() { LogDestiny Destiny = new LogDestiny(false, true, false); MessageTypeToLog TypeLog = new MessageTypeToLog(true, true, true); JobLogger Object = new JobLogger(Destiny, TypeLog); bool control = Object.LogMessage("TEST MESSAGE", LogType.Warning); Assert.IsTrue(!control); }
public void JobLogger_LogMessage_ToConsole_Message() { LogDestiny Destiny = new LogDestiny(true, false, false); MessageTypeToLog TypeLog = new MessageTypeToLog(true, true, true); JobLogger Object = new JobLogger(Destiny, TypeLog); bool control = Object.LogMessage("TEST MESSAGE", LogType.Message); Assert.IsTrue(control); }
public bool LogMessage(string message, LogType logType, MessageTypeToLog messageTypeToLog) { bool value = true; try { int typeMessage = (int)logType; string line = string.Empty; string directory = ConfigurationManager.AppSettings["LogFileDirectory"]; string stringDate = DateTime.Now.ToShortDateString(); string fullPath = string.Format("{0}{1}.txt", directory, stringDate); line = string.Format("{0}|{1}|{0}\n", DateTime.Now.ToShortDateString(), message, typeMessage); //this method create the files if doesnt exist File.AppendAllText(fullPath, line); } catch (Exception) { value = false; } return value; }
public JobLogger(LogDestiny logDestiny, MessageTypeToLog messageTypeToLog) { LogDestiny = logDestiny; MessageTypeToLog = messageTypeToLog; }
public void JobLogger_LogMessage_ToFile_Error() { LogDestiny Destiny = new LogDestiny(false, false, true); MessageTypeToLog TypeLog = new MessageTypeToLog(true, true, true); JobLogger Objeto = new JobLogger(Destiny, TypeLog); bool control = Objeto.LogMessage("TEST MESSAGE", LogType.Error); Assert.IsTrue(!control); }