Skip to content

Instantly share code, notes, and snippets.

@FDSoftware
Created March 13, 2019 03:16
Show Gist options
  • Save FDSoftware/f6ab7caf93e7dcbf37cdcc22f427d0ff to your computer and use it in GitHub Desktop.
Save FDSoftware/f6ab7caf93e7dcbf37cdcc22f427d0ff to your computer and use it in GitHub Desktop.
Logger para C#
Logger.Init(); //inicamos la wea llamar *1* vez, eso es mucho muy importante
Logger.Log("### Error Random ###");
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