2018-04-21 04:59:31 +00:00
|
|
|
using System;
|
2013-06-07 19:00:48 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NLog;
|
2015-02-07 12:22:03 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-06-07 19:00:48 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Common.Instrumentation
|
|
|
|
{
|
|
|
|
public static class GlobalExceptionHandlers
|
|
|
|
{
|
2014-12-17 07:12:26 +00:00
|
|
|
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(GlobalExceptionHandlers));
|
2013-06-07 19:00:48 +00:00
|
|
|
public static void Register()
|
|
|
|
{
|
2015-02-07 12:22:03 +00:00
|
|
|
AppDomain.CurrentDomain.UnhandledException += HandleAppDomainException;
|
|
|
|
TaskScheduler.UnobservedTaskException += HandleTaskException;
|
2013-06-07 19:00:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 12:22:03 +00:00
|
|
|
private static void HandleTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
2013-06-07 19:00:48 +00:00
|
|
|
{
|
2015-02-07 12:22:03 +00:00
|
|
|
var exception = e.Exception;
|
|
|
|
|
2013-06-07 19:00:48 +00:00
|
|
|
Console.WriteLine("Task Error: {0}", exception);
|
2016-02-11 21:13:42 +00:00
|
|
|
Logger.Error(exception, "Task Error: " + exception.Message);
|
2013-06-07 19:00:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 12:22:03 +00:00
|
|
|
private static void HandleAppDomainException(object sender, UnhandledExceptionEventArgs e)
|
2013-06-07 19:00:48 +00:00
|
|
|
{
|
2015-02-07 12:22:03 +00:00
|
|
|
var exception = e.ExceptionObject as Exception;
|
|
|
|
|
2013-09-14 19:59:06 +00:00
|
|
|
if (exception == null) return;
|
|
|
|
|
|
|
|
if (exception is NullReferenceException &&
|
|
|
|
exception.ToString().Contains("Microsoft.AspNet.SignalR.Transports.TransportHeartbeat.ProcessServerCommand"))
|
|
|
|
{
|
2015-04-28 14:28:05 +00:00
|
|
|
Logger.Warn("SignalR Heartbeat interupted");
|
2013-09-14 19:59:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-21 04:59:31 +00:00
|
|
|
if (PlatformInfo.IsMono)
|
2014-10-03 22:55:11 +00:00
|
|
|
{
|
2015-02-07 12:22:03 +00:00
|
|
|
if (exception is TypeInitializationException && exception.InnerException is DllNotFoundException ||
|
|
|
|
exception is DllNotFoundException)
|
|
|
|
{
|
2016-02-11 21:13:42 +00:00
|
|
|
Logger.Debug(exception, "Minor Fail: " + exception.Message);
|
2015-02-07 12:22:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-10-03 22:55:11 +00:00
|
|
|
}
|
2018-12-02 17:05:58 +00:00
|
|
|
|
|
|
|
Console.WriteLine(exception.StackTrace);
|
2015-02-07 12:22:03 +00:00
|
|
|
|
|
|
|
Console.WriteLine("EPIC FAIL: {0}", exception);
|
2016-02-11 21:13:42 +00:00
|
|
|
Logger.Fatal(exception, "EPIC FAIL: " + exception.Message);
|
2013-06-07 19:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-21 04:59:31 +00:00
|
|
|
}
|