Sonarr/src/NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs

59 lines
2.0 KiB
C#
Raw Normal View History

2013-06-07 19:00:48 +00:00
using System;
using System.Threading.Tasks;
using NLog;
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()
{
AppDomain.CurrentDomain.UnhandledException += HandleAppDomainException;
TaskScheduler.UnobservedTaskException += HandleTaskException;
2013-06-07 19:00:48 +00:00
}
private static void HandleTaskException(object sender, UnobservedTaskExceptionEventArgs e)
2013-06-07 19:00:48 +00:00
{
var exception = e.Exception;
if (exception.InnerException is ObjectDisposedException disposedException && disposedException.ObjectName == "System.Net.HttpListenerRequest")
{
// We don't care about web connections
return;
}
2013-06-07 19:00:48 +00:00
Console.WriteLine("Task Error: {0}", exception);
2017-01-05 23:32:17 +00:00
Logger.Error(exception, "Task Error");
2013-06-07 19:00:48 +00:00
}
private static void HandleAppDomainException(object sender, UnhandledExceptionEventArgs e)
2013-06-07 19:00:48 +00:00
{
var exception = e.ExceptionObject as Exception;
if (exception == null) return;
if (exception is NullReferenceException &&
exception.ToString().Contains("Microsoft.AspNet.SignalR.Transports.TransportHeartbeat.ProcessServerCommand"))
{
2018-01-22 14:24:11 +00:00
Logger.Warn("SignalR Heartbeat interrupted");
return;
}
if (PlatformInfo.IsMono)
2014-10-03 22:55:11 +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);
return;
}
2014-10-03 22:55:11 +00:00
}
Console.WriteLine("EPIC FAIL: {0}", exception);
Logger.Fatal(exception, "EPIC FAIL.");
2013-06-07 19:00:48 +00:00
}
}
2018-01-22 14:24:11 +00:00
}