From 7a3f7bf67c36f814c55eaafb59f2329c767360b1 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 1 Mar 2012 17:57:36 -0800 Subject: [PATCH] Fixed: Exceptions during Upgrade and AppStart are reported correctly. --- NzbDrone.Common/ReportingService.cs | 24 +++++++++++++++++++----- NzbDrone.Common/RestProvider.cs | 2 +- NzbDrone.Update/Program.cs | 9 +++++---- NzbDrone/CentralDispatch.cs | 2 ++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/NzbDrone.Common/ReportingService.cs b/NzbDrone.Common/ReportingService.cs index 0ab413e17..834d136ac 100644 --- a/NzbDrone.Common/ReportingService.cs +++ b/NzbDrone.Common/ReportingService.cs @@ -30,8 +30,7 @@ namespace NzbDrone.Common { try { - if (RestProvider == null && EnviromentProvider.IsProduction) - return; + VerifyRestProvider(); lock (parserErrorCache) { @@ -59,9 +58,8 @@ namespace NzbDrone.Common { try { - if (RestProvider == null && EnviromentProvider.IsProduction) - return; - + VerifyRestProvider(); + var report = new ExceptionReport(); report.LogMessage = logEvent.FormattedMessage; report.String = logEvent.Exception.ToString(); @@ -81,5 +79,21 @@ namespace NzbDrone.Common logger.Info("Unable to report exception. " + e); } } + + private static void VerifyRestProvider() + { + if(RestProvider == null) + { + if(EnviromentProvider.IsProduction) + { + logger.Warn("Rest provider wasn't provided. creating new one!"); + RestProvider = new RestProvider(new EnviromentProvider()); + } + else + { + throw new InvalidOperationException("REST Provider wasn't configured correctly."); + } + } + } } } diff --git a/NzbDrone.Common/RestProvider.cs b/NzbDrone.Common/RestProvider.cs index 4dc4da867..ac85a3010 100644 --- a/NzbDrone.Common/RestProvider.cs +++ b/NzbDrone.Common/RestProvider.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Common public class RestProvider { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private readonly EnviromentProvider _enviromentProvider; diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index d159133fe..eeadaaf41 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -2,8 +2,6 @@ using System.IO; using System.Linq; using NLog; -using NLog.Config; -using NLog.Targets; using Ninject; using NzbDrone.Common; using NzbDrone.Update.Providers; @@ -29,9 +27,10 @@ namespace NzbDrone.Update try { Console.WriteLine("Starting NzbDrone Update Client"); - - InitLoggers(); _kernel = new StandardKernel(); + InitLoggers(); + + logger.Info("Updating NzbDrone to version {0}", _kernel.Get().Version); _kernel.Get().Start(args); @@ -62,6 +61,8 @@ namespace NzbDrone.Update private static void InitLoggers() { + ReportingService.RestProvider = _kernel.Get(); + LogConfiguration.RegisterRemote(); LogConfiguration.RegisterConsoleLogger(LogLevel.Trace); diff --git a/NzbDrone/CentralDispatch.cs b/NzbDrone/CentralDispatch.cs index 46d8c45f3..fe5c7383f 100644 --- a/NzbDrone/CentralDispatch.cs +++ b/NzbDrone/CentralDispatch.cs @@ -44,6 +44,8 @@ namespace NzbDrone private static void InitilizeApp() { var enviromentProvider = _kernel.Get(); + + ReportingService.RestProvider = _kernel.Get(); LogConfiguration.RegisterRollingFileLogger(enviromentProvider.GetLogFileName(), LogLevel.Info); LogConfiguration.RegisterConsoleLogger(LogLevel.Debug);