Last active
October 27, 2020 07:55
-
-
Save Krilliac/75c93d0933121608a04883074dadbccc to your computer and use it in GitHub Desktop.
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
private static async Task PutTaskDelay() | |
{ | |
await Task.Delay(8_000); //8 seconds, split by a digit separator | |
} | |
private async void GenericExceptionHandler(object sender, UnhandledExceptionEventArgs e) | |
{ | |
try | |
{ | |
var ex = (Exception)e.ExceptionObject; | |
Log.WriteLine(LogType.CRITICAL, ex + Environment.NewLine); | |
Log.WriteLine(LogType.FAILED, | |
"Unexpected error has occured. An 'AppName-Error-yyyy-mmm-d-h-mm.log' file has been created. Check your log folder for more information."); | |
await using TextWriter tw = new StreamWriter(new FileStream($"AppName-Error-{Strings.Format(DateTime.Now, "yyyy-MMM-d-H-mm")}.log", FileMode.Create)); | |
await tw.WriteAsync(ex.ToString()); | |
tw.Close(); | |
await tw.DisposeAsync(); | |
await PutTaskDelay(); //Hold, but allow console to remain active for time defined in PutTaskDelay() | |
{ | |
Environment.ExitCode = -1; //Finish up any remaining resources & threads, then stop | |
} | |
} | |
catch (Exception) | |
{ | |
Environment.Exit(-1); //Hard stop, close out no matter what | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LogType is a custom logger, for my project. Console.WriteLine or other alternatives may need to be implemented