I\'ve written simple server using Owin Self-hosting and WebApi:
namespace OwinSelfHostingTest
{
using System.Threading;
using System.Web.Http;
us
When you await a async method, an exception won't be thrown into the caller's context, but will be available by inspecting the task returned to the caller.
So, with this modification to the solution provided by @yuval-itzchakov you'll be able to capture underlying exceptions:
var subtask = Next.Invoke(context);
await subtask;
if (subtask.Exception != null)
{
// log subtask.Exception here
}