consolidate exception logging
This commit is contained in:
parent
70c5b341db
commit
1923de72bf
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -174,9 +174,9 @@ namespace MediaBrowser.ServerApplication
|
|||
|
||||
cmdExit.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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user