Log request in ASP.NET Web Api

I am trying to log all posted data in my WebApi when an exception is thrown. I tried this:

protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
    if (request.Content == null) 
        return await base.SendAsync(request, cancellationToken);

    var Body = await request.Content.ReadAsStringAsync();

    request.Properties["body"] = Body;

    return await base.SendAsync(request, cancellationToken);
}

      

And in my error log method I am getting posted values ​​in Properties["body"]

.

But when users upload the image, I get this when I try to get the files:

This method or property is not supported after calling HttpRequest.GetBufferlessInputStream.
at System.Web.HttpRequest.get_Files ()

How can I keep only published ones data(text)

in this property?

+3


source to share





All Articles