public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken) { JObject json = converter.ToJObject(new { context.Exception, Trace = EnumeratorUtil.Generate(new StringReader(context.Exception.StackTrace).ReadLine).ToArray(), Request = new { Headers = context.Request.Headers.ToDictionary(pair => pair.Key, p => p.Value), RequestUri = context.Request.RequestUri.ToString(), context.Request.Method.Method, Body = ReadPayload(context), Version = context.Request.Version.ToString() } }); string message = context.Exception.Message; return(Task.Factory.StartNew(() => { try { logger.LogFailure(Severity.Error, message, json); } catch (Exception ex) { dump.Dump("Failed to log error to diagnostic log: " + Environment.NewLine + Environment.NewLine + ex); } }, cancellationToken)); }