Skip to content

Instantly share code, notes, and snippets.

@Whistler092
Created August 3, 2018 20:10
Show Gist options
  • Save Whistler092/fa702b707d1742b1f0a2b14317c27a0b to your computer and use it in GitHub Desktop.
Save Whistler092/fa702b707d1742b1f0a2b14317c27a0b to your computer and use it in GitHub Desktop.
Easy way to save exception on file
internal static void LocalLog(Exception trace)
{
try
{
string InfoText = string.Empty;
if (trace != null)
{
InfoText += Environment.NewLine + Newtonsoft.Json.JsonConvert.SerializeObject(trace, Newtonsoft.Json.Formatting.Indented)
+ Environment.NewLine;
}
var path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var logfile = path + "\\" + DateTime.Now.Year + "." + DateTime.Now.Month + "." + DateTime.Now.Day + " WSRecaudoTercero.log";
File.AppendAllText(logfile, DateTime.Now + " - " + Environment.NewLine + InfoText + Environment.NewLine + Environment.NewLine);
}
catch
{
//asdf
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment