microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
566 stars 285 forks source link

Optionally log POST request body #1880

Closed kendaleiv closed 2 years ago

kendaleiv commented 4 years ago

Previously reported here: https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/686

Sounds like it may be happening per https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/686#issuecomment-545531512 but didn't want it to fall off the radar for those who would find it useful.

cijothomas commented 4 years ago

Its not lost! its among the top asks in uservoice! Unfortunately, this is not going to be supported by the ApplicationInsights SDK in this year.

The current suggestion/workaround is for customers to write the RequestBody using Ilogger. And have application insights capture the ilogger trace. Since ilogger traces gets automatically correlated with Request telemetry, it should be possible to find the body.

leninc commented 4 years ago

Hi @cijothomas! do you happen to have a sample for the item above, i have an mvc project in 4.6 that i want to be able to log the request and response to app insights and not sure what approach to take based on the comment here.

Regards

cijothomas commented 4 years ago

@leninc The recommendation currently is: Get request/response body - log it using ilogger instance. Configure application insights to capture it - if the ilogger is logged at Warning level or above, the Application Insights collects it by default. Else modify filters to capture it. (https://docs.microsoft.com/en-us/azure/azure-monitor/app/ilogger#control-logging-level)

I don't have working sample to correctly capture request/response body. For logging with Ilogger, the official docs has examples.

leninc commented 4 years ago

@cijothomas thanks for the quick response, will look into this

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

cijothomas commented 2 years ago

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-logging/?view=aspnetcore-6.0 .New middleware from asp.net core 6.0 makes this easy to do.

Postlagerkarte commented 8 months ago

@cijothomas I activated the new HttpLogging middleware, can see the output from it in my console window, however it is not visible/attached to my App Insights. What am I missing?