2013-06-07 19:00:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception));
|
|
|
|
|
TaskScheduler.UnobservedTaskException += ((s, e) => TaskException(e.Exception));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void TaskException(Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Task Error: {0}", exception);
|
|
|
|
|
Logger.Error("Task Error: " + exception.Message, exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void AppDomainException(Exception 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"))
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("SignalR Heartbeat error.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 19:00:48 +00:00
|
|
|
|
Console.WriteLine("EPIC FAIL: {0}", exception);
|
|
|
|
|
Logger.FatalException("EPIC FAIL: " + exception.Message, exception);
|
2014-10-03 22:55:11 +00:00
|
|
|
|
|
|
|
|
|
if (exception.InnerException != null)
|
|
|
|
|
{
|
|
|
|
|
AppDomainException(exception.InnerException);
|
|
|
|
|
}
|
2013-06-07 19:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|