Created
August 3, 2018 20:10
-
-
Save Whistler092/fa702b707d1742b1f0a2b14317c27a0b to your computer and use it in GitHub Desktop.
Easy way to save exception on file
This file contains hidden or 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
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