Created
March 13, 2019 03:16
-
-
Save FDSoftware/f6ab7caf93e7dcbf37cdcc22f427d0ff to your computer and use it in GitHub Desktop.
Logger para C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Logger.Init(); //inicamos la wea llamar *1* vez, eso es mucho muy importante | |
Logger.Log("### Error Random ###"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
namespace XXXX | |
{ | |
class Logger { | |
public static string nombre = ""; //nombre del archivo de log | |
//logger para debug /control de errores | |
public static void Init(){ | |
//aca creo el archivo para el log | |
DateTime dateTime = new DateTime(); | |
dateTime = DateTime.Now; | |
nombre = "log " + Convert.ToDateTime(dateTime).ToString("MM-dd") + ".txt"; | |
if ( !System.IO.File.Exists(nombre) ) | |
Logger.Log("archivo creado"); | |
} | |
public static void Log(string txt){ | |
DateTime dateTime = new DateTime(); | |
dateTime = DateTime.Now; | |
nombre = "log " + Convert.ToDateTime(dateTime).ToString("MM-dd") + ".txt"; | |
StreamWriter sw = new StreamWriter(nombre); | |
string temp = txt += ": "; | |
temp += Convert.ToDateTime(dateTime).ToString("hh:mm:ss"); | |
sw.WriteLine(temp); | |
sw.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment