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 @@ public static void ReportParseError(string title) { try { - if (RestProvider == null && EnviromentProvider.IsProduction) - return; + VerifyRestProvider(); lock (parserErrorCache) { @@ -59,9 +58,8 @@ public static void ReportException(LogEventInfo logEvent) { 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 @@ public static void ReportException(LogEventInfo logEvent) 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 @@ public static void Main(string[] args) 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 @@ private static void TransferUpdateLogs() 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 @@ private static void BindKernel() private static void InitilizeApp() { var enviromentProvider = _kernel.Get(); + + ReportingService.RestProvider = _kernel.Get(); LogConfiguration.RegisterRollingFileLogger(enviromentProvider.GetLogFileName(), LogLevel.Info); LogConfiguration.RegisterConsoleLogger(LogLevel.Debug);