public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { ILogger logger = new NLogLogger("logs.txt"); if (eventArgs.ExceptionObject is Exception e) { logger.Error(FailureString, e); } else { logger.Error(FailureString + eventArgs.ExceptionObject); } }; try { Run(args); } catch (AggregateException e) { ILogger logger = new NLogLogger("logs.txt"); logger.Error(FailureString, e.InnerException); } catch (Exception e) { ILogger logger = new NLogLogger("logs.txt"); logger.Error(FailureString, e); } finally { NLogLogger.Shutdown(); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { ILogger logger = new NLogLogger("logs.txt"); if (eventArgs.ExceptionObject is Exception e) { logger.Error(FailureString, e); } else { logger.Error(FailureString + eventArgs.ExceptionObject?.ToString()); } }; try { IRunnerApp runner = new RunnerApp(); runner.Run(args); return; } catch (AggregateException e) { ILogger logger = new NLogLogger("logs.txt"); logger.Error(FailureString, e.InnerException); } catch (Exception e) { ILogger logger = new NLogLogger("logs.txt"); logger.Error(FailureString, e); } finally { NLogLogger.Shutdown(); } Console.WriteLine("Press RETURN to exit."); Console.ReadLine(); }