Radarr/NzbDrone.Common/TPL/TaskExtensions.cs

26 lines
725 B
C#
Raw Normal View History

2013-07-12 06:10:34 +00:00
using System.Threading.Tasks;
using NLog;
2013-08-31 01:42:30 +00:00
using NzbDrone.Common.Instrumentation;
2013-07-12 06:10:34 +00:00
namespace NzbDrone.Common.TPL
{
public static class TaskExtensions
{
2013-08-31 01:42:30 +00:00
private static readonly Logger Logger = NzbDroneLogger.GetLogger();
2013-07-12 06:10:34 +00:00
public static Task LogExceptions(this Task task)
{
task.ContinueWith(t =>
{
var aggregateException = t.Exception.Flatten();
foreach (var exception in aggregateException.InnerExceptions)
{
Logger.ErrorException("Task Error", exception);
}
}, TaskContinuationOptions.OnlyOnFaulted);
return task;
}
}
}