mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-25 17:17:02 +00:00
added common global exception handler.
This commit is contained in:
parent
89082ea94e
commit
53c32fbe10
4 changed files with 38 additions and 12 deletions
31
NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs
Normal file
31
NzbDrone.Common/Instrumentation/GlobalExceptionHandlers.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
public static class GlobalExceptionHandlers
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetLogger("Global");
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
ExceptronTarget.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)
|
||||
{
|
||||
Console.WriteLine("EPIC FAIL: {0}", exception);
|
||||
Logger.FatalException("EPIC FAIL: " + exception.Message, exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -103,6 +103,7 @@
|
|||
<Compile Include="EnsureThat\ExpressionExtensions.cs" />
|
||||
<Compile Include="EnsureThat\Param.cs" />
|
||||
<Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" />
|
||||
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
||||
<Compile Include="Instrumentation\ExceptronTarget.cs" />
|
||||
<Compile Include="Messaging\LimitedConcurrencyLevelTaskScheduler.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
|
|
|
@ -27,10 +27,9 @@ public static void Main(string[] args)
|
|||
try
|
||||
{
|
||||
Console.WriteLine("Starting NzbDrone Update Client");
|
||||
GlobalExceptionHandlers.Register();
|
||||
|
||||
new LogglyTarget(new EnvironmentProvider()).Register(LogLevel.Debug);
|
||||
|
||||
ExceptronTarget.Register();
|
||||
|
||||
_container = UpdateContainerBuilder.Build();
|
||||
|
||||
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<IEnvironmentProvider>().Version);
|
||||
|
@ -40,7 +39,6 @@ public static void Main(string[] args)
|
|||
{
|
||||
logger.FatalException("An error has occurred while applying update package.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Start(string[] args)
|
||||
|
|
|
@ -16,12 +16,13 @@ public static void Main(string[] args)
|
|||
{
|
||||
try
|
||||
{
|
||||
GlobalExceptionHandlers.Register();
|
||||
|
||||
new LogglyTarget(new EnvironmentProvider()).Register(LogLevel.Warn);
|
||||
ExceptronTarget.Register();
|
||||
|
||||
|
||||
logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception));
|
||||
|
||||
//Check if full version .NET is installed.
|
||||
try
|
||||
|
@ -61,14 +62,9 @@ public static void Main(string[] args)
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AppDomainException(e);
|
||||
logger.FatalException("Epic Fail " + e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AppDomainException(Exception exception)
|
||||
{
|
||||
Console.WriteLine("EPIC FAIL: {0}", exception);
|
||||
logger.FatalException("EPIC FAIL: " + exception.Message, exception);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue