Is there any way to include the HTTP Body response content in Application Insights HTTP or dependency tracking modules? Its useful knowing what the HTTP response status code of a request is, but its really important us to know what the response message/data.
Ive looked at creating a custom Filter or Initializer but no properties seem to have any response content, how can I include it?
This actually requires a bit more than inspecting the properties of your Response object. You will have to use a Response Filter in order to capture the body before it's done.
The gist below has two files. One is the CaptureStream.cs
file that implements a Stream abastract class and just passes along the information. Along the way we append data in a StringBuilder.
In the other is just an example of a Global.asax.cs
that overrides the Application_BeginRequest
method and the Application_LogRequest
method.
You can choose any method in the ASP.NET Application Lifecycle that you think is the right location. I chose these two because it was the first two I remember using in other projects.
https://gist.github.com/debugthings/058f8c0634accfbdcce2c8c5b818d514
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With