added common global exception handler.

pull/3113/head
Keivan Beigi 12 years ago
parent 89082ea94e
commit 53c32fbe10

@ -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 @@ namespace NzbDrone.Update
try
{
Console.WriteLine("Starting NzbDrone Update Client");
new LogglyTarget(new EnvironmentProvider()).Register(LogLevel.Debug);
ExceptronTarget.Register();
GlobalExceptionHandlers.Register();
new LogglyTarget(new EnvironmentProvider()).Register(LogLevel.Debug);
_container = UpdateContainerBuilder.Build();
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<IEnvironmentProvider>().Version);
@ -40,7 +39,6 @@ namespace NzbDrone.Update
{
logger.FatalException("An error has occurred while applying update package.", e);
}
}
public void Start(string[] args)

@ -16,12 +16,13 @@ namespace NzbDrone
{
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 @@ namespace NzbDrone
}
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…
Cancel
Save