safer log configuration

This commit is contained in:
Keivan Beigi
2014-12-16 23:12:26 -08:00
parent b7b4c568be
commit 0a341199a8
33 changed files with 281 additions and 296 deletions
+7 -5
View File
@@ -6,18 +6,20 @@ namespace NzbDrone.Common.TPL
{
public static class TaskExtensions
{
private static readonly Logger Logger = NzbDroneLogger.GetLogger();
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(TaskExtensions));
public static Task LogExceptions(this Task task)
{
task.ContinueWith(t =>
{
var aggregateException = t.Exception.Flatten();
foreach (var exception in aggregateException.InnerExceptions)
if (t.Exception != null)
{
Logger.ErrorException("Task Error", exception);
var aggregateException = t.Exception.Flatten();
foreach (var exception in aggregateException.InnerExceptions)
{
Logger.ErrorException("Task Error", exception);
}
}
}, TaskContinuationOptions.OnlyOnFaulted);
return task;