What is the best way to register an HTTP request body when a request fails?
I register unhandled exceptions by overriding the exception logger:
public class AiExceptionLogger : ExceptionLogger
{
public override void Log(ExceptionLoggerContext context)
{
if (context != null && context.Exception != null)
{
ExceptionTelemetry telemetry = new ExceptionTelemetry(context.Exception);
string requestBody = context.Request.Content.ReadAsStringAsync().Result;
telemetry.Properties.Add("Request Body", requestBody);
Logger.LogException(telemetry);
}
base.Log(context);
}
}
With the above code, the contents of the request are always empty. I also tried this one , but this throws an unsupported method exception due to a call to GetBufferlessInputStream. So it doesn’t work either.
I can register all request content with the DelegatingHandler, but I would only like to register the request body with failed requests caused by unhandled exceptions.
Any ideas?