using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ServerCore; public struct DumpConfig { public string DumpFile; public string TxtFile; } public static class DumpHandler { public static void unhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e) { var exception = e.ExceptionObject as Exception; File.WriteAllText("unhandled_exception.log", exception?.ToString()); writeTxt(DumpHelper.DumpConfig, exception); } public static void writeTxt(DumpConfig dumpCopnfig, Exception? e) { using (var fs = new FileStream(dumpCopnfig.TxtFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Write)) { using (StreamWriter writer = new StreamWriter(fs)) { writer.WriteLine("================================================================================================"); writer.WriteLine("Date : " + DateTime.Now.ToString()); writer.WriteLine(); Exception? exception = e; while (exception != null) { writer.WriteLine($"{exception}"); writer.WriteLine("================================================================================================"); exception = exception.InnerException; } } } } }