From f1248d12c66674d289f81c7f1157e5af4d51475f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 16 Oct 2011 18:42:20 -0700 Subject: [PATCH] Better exception handling in NzbDrone.exe --- NzbDrone/AppMain.cs | 9 ++------- NzbDrone/Providers/MonitoringProvider.cs | 9 +++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/NzbDrone/AppMain.cs b/NzbDrone/AppMain.cs index 801ffae68..f794f9093 100644 --- a/NzbDrone/AppMain.cs +++ b/NzbDrone/AppMain.cs @@ -1,16 +1,12 @@ using System; using System.Reflection; -using NLog; using Ninject; +using NzbDrone.Providers; namespace NzbDrone { public static class AppMain { - - - private static readonly Logger Logger = LogManager.GetLogger("Host.Main"); - public static void Main(string[] args) { try @@ -21,8 +17,7 @@ namespace NzbDrone } catch (Exception e) { - Console.WriteLine(e.ToString()); - Logger.Fatal(e.ToString()); + MonitoringProvider.AppDomainException(e); } } diff --git a/NzbDrone/Providers/MonitoringProvider.cs b/NzbDrone/Providers/MonitoringProvider.cs index 0fa5a1562..1ebd317e8 100644 --- a/NzbDrone/Providers/MonitoringProvider.cs +++ b/NzbDrone/Providers/MonitoringProvider.cs @@ -34,7 +34,7 @@ namespace NzbDrone.Providers public void Start() { - AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e)); + AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception)); AppDomain.CurrentDomain.ProcessExit += ProgramExited; AppDomain.CurrentDomain.DomainUnload += ProgramExited; @@ -43,7 +43,7 @@ namespace NzbDrone.Providers prioCheckTimer.Elapsed += EnsurePriority; prioCheckTimer.Enabled = true; - _pingTimer = new Timer(60000) {AutoReset = true}; + _pingTimer = new Timer(60000) { AutoReset = true }; _pingTimer.Elapsed += (PingServer); _pingTimer.Start(); } @@ -102,10 +102,9 @@ namespace NzbDrone.Providers } - private static void AppDomainException(object excepion) + public static void AppDomainException(Exception excepion) { Console.WriteLine("EPIC FAIL: {0}", excepion); - Logger.Fatal("EPIC FAIL: {0}", excepion); #if DEBUG #else @@ -116,6 +115,8 @@ namespace NzbDrone.Providers CurrentException = excepion as Exception }.Submit(); #endif + + Logger.Fatal("EPIC FAIL: {0}", excepion); } } } \ No newline at end of file