View POST request body in Application Insights

前端 未结 9 1574
抹茶落季
抹茶落季 2020-11-29 17:48

Is it possible to view POST request body in Application Insights?

I can see request details, but not the payload being posted in application insights. Do I have to t

9条回答
  •  隐瞒了意图╮
    2020-11-29 18:12

    The solution provided by yonisha is clean, but it does not work for me in .Net Core 2.0. This works if you have a JSON body:

    public IActionResult MyAction ([FromBody] PayloadObject payloadObject)
    {
        //create a dictionary to store the json string
        var customDataDict = new Dictionary();
    
        //convert the object to a json string
        string activationRequestJson = JsonConvert.SerializeObject(
        new
        {
            payloadObject = payloadObject
        });
    
        customDataDict.Add("body", activationRequestJson);
    
        //Track this event, with the json string, in Application Insights
        telemetryClient.TrackEvent("MyAction", customDataDict);
    
        return Ok();
    }
    

提交回复
热议问题