The Free Software Media System - Server Backend & API
consolidate exception logging
Luke Pulverenti1923de72bf3c
diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.jsonindex 84494f8bd7..45dab6a571 100644--- a/MediaBrowser.Server.Implementations/Localization/Server/server.json+++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json@@ -1,10 +1,11 @@{"LabelExit": "Exit","LabelVisitCommunity": "Visit Community",- "LabelGithubWiki": "Github Wiki",+ "LabelGithub": "Github","LabelSwagger": "Swagger","LabelStandard": "Standard",- "LabelViewApiDocumentation": "View Api Documentation",+ "LabelApiDocumentation": "Api Documentation",+ "LabelDeveloperResources": "Developer Resources","LabelBrowseLibrary": "Browse Library","LabelConfigureMediaBrowser": "Configure Media Browser","LabelOpenLibraryViewer": "Open Library Viewer",diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.csindex 8a34488c62..2fb9838508 100644--- a/MediaBrowser.Server.Mono/Program.cs+++ b/MediaBrowser.Server.Mono/Program.cs@@ -7,7 +7,6 @@ using MediaBrowser.Server.Startup.Common;using Microsoft.Win32;using System;using System.Diagnostics;-using System.IO;using System.Net;using System.Net.Security;using System.Reflection;@@ -124,7 +123,7 @@ namespace MediaBrowser.Server.Mono{var exception = (Exception)e.ExceptionObject;- LogUnhandledException(exception);+ new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);if (!Debugger.IsAttached){@@ -132,22 +131,6 @@ namespace MediaBrowser.Server.Mono}}- private static void LogUnhandledException(Exception ex)- {- _logger.ErrorException("UnhandledException", ex);-- _appHost.LogManager.Flush ();-- var path = Path.Combine(_appHost.ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, "crash_" + Guid.NewGuid() + ".txt");-- var builder = LogHelper.GetLogMessage(ex);-- Console.WriteLine ("UnhandledException");- Console.WriteLine (builder.ToString());-- File.WriteAllText(path, builder.ToString());- }-public static void Shutdown(){ApplicationTaskCompletionSource.SetResult (true);diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csprojindex 474dadfe28..46a7710272 100644--- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj+++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj@@ -70,6 +70,7 @@<Compile Include="NativeEnvironment.cs" /><Compile Include="Properties\AssemblyInfo.cs" /><Compile Include="StartupOptions.cs" />+ <Compile Include="UnhandledExceptionWriter.cs" /></ItemGroup><ItemGroup><ProjectReference Include="..\MediaBrowser.Api\MediaBrowser.Api.csproj">diff --git a/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs b/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.csnew file mode 100644index 0000000000..96c24eaabf--- /dev/null+++ b/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs@@ -0,0 +1,39 @@+using MediaBrowser.Common.Configuration;+using MediaBrowser.Common.Implementations.Logging;+using MediaBrowser.Model.Logging;+using System;+using System.IO;++namespace MediaBrowser.Server.Startup.Common+{+ public class UnhandledExceptionWriter+ {+ private readonly IApplicationPaths _appPaths;+ private readonly ILogger _logger;+ private readonly ILogManager _logManager;++ public UnhandledExceptionWriter(IApplicationPaths appPaths, ILogger logger, ILogManager logManager)+ {+ _appPaths = appPaths;+ _logger = logger;+ _logManager = logManager;+ }++ public void Log(Exception ex)+ {+ _logger.ErrorException("UnhandledException", ex);+ _logManager.Flush();++ var path = Path.Combine(_appPaths.LogDirectoryPath, "unhandled_" + Guid.NewGuid() + ".txt");+ Directory.CreateDirectory(Path.GetDirectoryName(path));++ var builder = LogHelper.GetLogMessage(ex);++ // Write to console just in case file logging fails+ Console.WriteLine("UnhandledException");+ Console.WriteLine(builder.ToString());++ File.WriteAllText(path, builder.ToString());+ }+ }+}diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.csindex d98f3e2651..8974ca8da6 100644--- a/MediaBrowser.ServerApplication/MainStartup.cs+++ b/MediaBrowser.ServerApplication/MainStartup.cs@@ -455,9 +455,7 @@ namespace MediaBrowser.ServerApplication{var exception = (Exception)e.ExceptionObject;- LogUnhandledException(exception);-- _appHost.LogManager.Flush();+ new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);if (!_isRunningAsService){@@ -470,18 +468,6 @@ namespace MediaBrowser.ServerApplication}}- private static void LogUnhandledException(Exception ex)- {- _logger.ErrorException("UnhandledException", ex);-- var path = Path.Combine(_appHost.ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, "unhandled_" + Guid.NewGuid() + ".txt");- Directory.CreateDirectory(Path.GetDirectoryName(path));-- var builder = LogHelper.GetLogMessage(ex);-- File.WriteAllText(path, builder.ToString());- }-/// <summary>/// Performs the update if needed./// </summary>diff --git a/MediaBrowser.ServerApplication/ServerNotifyIcon.cs b/MediaBrowser.ServerApplication/ServerNotifyIcon.csindex 6e13bb791c..e3e1359d9a 100644--- a/MediaBrowser.ServerApplication/ServerNotifyIcon.cs+++ b/MediaBrowser.ServerApplication/ServerNotifyIcon.cs@@ -174,9 +174,9 @@ namespace MediaBrowser.ServerApplicationcmdExit.Text = _localization.GetLocalizedString("LabelExit");cmdCommunity.Text = _localization.GetLocalizedString("LabelVisitCommunity");- cmdGtihub.Text = _localization.GetLocalizedString("LabelGithubWiki");- cmdSwagger.Text = _localization.GetLocalizedString("LabelSwagger");- cmdApiDocs.Text = _localization.GetLocalizedString("LabelViewApiDocumentation");+ cmdGtihub.Text = _localization.GetLocalizedString("LabelGithub");+ cmdSwagger.Text = _localization.GetLocalizedString("LabelApiDocumentation");+ cmdApiDocs.Text = _localization.GetLocalizedString("LabelDeveloperResources");cmdBrowse.Text = _localization.GetLocalizedString("LabelBrowseLibrary");cmdConfigure.Text = _localization.GetLocalizedString("LabelConfigureMediaBrowser");cmdRestart.Text = _localization.GetLocalizedString("LabelRestartServer");