added exception logging to Tasks.

This commit is contained in:
kay.one 2013-07-11 23:10:34 -07:00
parent 508b087c46
commit d607b831c9
7 changed files with 39 additions and 6 deletions

View file

@ -0,0 +1,25 @@
using System.Threading.Tasks;
using NLog;
namespace NzbDrone.Common.TPL
{
public static class TaskExtensions
{
private static readonly Logger Logger = LogManager.GetLogger("TaskExtensions");
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;
}
}
}