public static void Main(string[] args) { AppContext.SetSwitch("Switch.MS.Internal.DoNotInvokeInWeakEventTableShutdownListener", true); if (string.IsNullOrWhiteSpace(csExceptionLogger.csExceptionLogger.DefaultLogLocation)) { csExceptionLogger.csExceptionLogger.DefaultLogLocation = $@"\\joi\EU\Public\EE Process Test\Logs\RApID\_Exceptions\{DateTime.Today:yyyy}\{DateTime.Today:MMMM}\"; Directory.CreateDirectory(csExceptionLogger.csExceptionLogger.DefaultLogLocation); } try { App application = new App(); application.InitializeComponent(); application.Run(); } catch (Exception e) { Mailman.SendEmail(subject: "", body: "", exception: e); throw; } }
public MainWindow() { holder.vGetServerName(""); csExceptionLogger.csExceptionLogger.DefaultLogLocation = $@"\\joi\EU\Public\_Error Logs\{AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "")}\{DateTime.Now:yyyy-MM-dd}"; if (!Directory.Exists(csExceptionLogger.csExceptionLogger.DefaultLogLocation)) { Directory.CreateDirectory(csExceptionLogger.csExceptionLogger.DefaultLogLocation); } InitializeComponent(); #if DEBUG lblDebug.Visibility = Visibility.Visible; btnTest.Visibility = Visibility.Visible; #endif Notify = notifyRapid; GlobalInstance = this; // attempted to fix visual studio exception on stopping debugging AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( delegate(object sender, UnhandledExceptionEventArgs args) { Exception e = ((Exception)args.ExceptionObject); var out_msg = $"[UnhandledExceptionHandler]: {e.Message}\n" + $"(Stack Trace)\n{new string('-', 20)}\n\n{e.StackTrace}\n\n{new string('-', 20)}\n" + $"Will runtime terminate now? -> \'{(args.IsTerminating ? "Yes" : "No")}\'"; Console.WriteLine(out_msg); #if !DEBUG Mailman.SendEmail(subject: "", body: "", exception: e); #endif if (e is TaskCanceledException tce) { var err_msg = $"[UnhandledException] Task: {tce.Task.Id} | CanBeCanceled = {tce.CancellationToken.CanBeCanceled}\n\tSource -> {tce.Source}"; #if !DEBUG csExceptionLogger.csExceptionLogger.Write("Unhandled_Exception", e); #endif Console.WriteLine(err_msg); } }); AppDomain.CurrentDomain.FirstChanceException += new EventHandler <System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs>( delegate(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs args) { Exception e = args.Exception; var out_msg = $"[FirstChanceHandler]: {e.Message}\n" + $"(Stack Trace)\n{new string('-', 20)}\n\n{e.StackTrace}\n"; Console.WriteLine(out_msg); if (e is TaskCanceledException tce) { var err_msg = $"[FirstChanceException] Task ID: {tce.Task.Id} | CanBeCanceled = {tce.CancellationToken.CanBeCanceled}\n\tSource -> {tce.Source}"; #if !DEBUG csExceptionLogger.csExceptionLogger.Write("FirstChance_Exception", e); #endif Console.WriteLine(err_msg); } }); }