public void TestMethod1() { Loggear log = new Loggear(); JobLogger jobLog = new JobLogger(); log._logWarning = false; log._logToFile = true; log._logToConsole = false; log._logError = true; log.mensaje = "Prueba de logeo de Belatrix .Net!"; jobLog.LogMessage(log); }
public void GuardaLogEnArchivo(Loggear log) { string l = string.Empty ; if (!System.IO.File.Exists(System.Configuration.ConfigurationManager.AppSettings["LogFileDirectory"] + "LogFile" + DateTime.Now.ToShortDateString() + ".txt")) { l = System.IO.File.ReadAllText(System.Configuration.ConfigurationManager.AppSettings["LogFileDirectory"] + "LogFile" + DateTime.Now.ToShortDateString() + ".txt"); } if (log._logError) { l += Mensajes.Mensajes + DateTime.Now.ToShortDateString() + log._logMessage; } if (log._logWarning) { l += Mensajes.Warning + DateTime.Now.ToShortDateString() + log._logWarning; } if (log._logMessage) { l += Mensajes.Error + DateTime.Now.ToShortDateString() + log._logMessage; } System.IO.File.WriteAllText(System.Configuration.ConfigurationManager.AppSettings[ "LogFileDirectory"] + "LogFile" + DateTime.Now.ToShortDateString() + ".txt", l); }
public void GuardarLogDB(Loggear log) { int t; if (log._logMessage) t=1; else if(log._logError) t=2; else t=3; System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]); connection.Open(); System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("Insert into Log Values('" + log.mensaje + "', " + t.ToString() + ")"); command.ExecuteNonQuery(); }
public void MuestrPorPantalla(Loggear log) { if (log._logError) { Console.ForegroundColor = ConsoleColor.Red; } if (log._logWarning) { Console.ForegroundColor = ConsoleColor.Yellow; } if (log._logMessage) { Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(DateTime.Now.ToShortDateString() + log.mensaje); }
public void LogMessage(Loggear log) { if (log==null) { if (!log._logToConsole&& !log._logToFile&& !log.LogToDatabase) ThrowException("Configuración Invalida"); if (!log._logError && !log._logMessage&& !log._logWarning) ThrowException("Error or Warning or Message must be specified"); MuestraPorConsola consola = new MuestraPorConsola(); GuardaEnArchivo archivo = new GuardaEnArchivo(); if(log._logToConsole) consola.MuestrPorPantalla(log); if(log._logToFile) archivo.GuardaLogEnArchivo(log); if(log.LogToDatabase) GuardaEnBaseDeDatos.Instance.GuardarLogDB(log); } }