简体   繁体   English

如何将ASP.NET Web API请求正文记录到Application Insights故障中?

[英]How to log ASP.NET Web API request body into a Application Insights failure?

I'm logging my unhandled exceptions in an ExceptionLogger using the TelemetryClient to Application Insights on Azure. 我使用TelemetryClient将未处理的异常记录在ExceptionLogger中,以记录到Azure上的Application Insights。

public class GlobalExceptionLogger : ExceptionLogger
{
    public override void Log(ExceptionLoggerContext context)
    {
        if (context != null && context.Exception != null)
        {
              //For simplification a new TelemetryClient instance
              //This is not recommended!
              new TelemetryClient().TrackException(context.Exception);
        }
        base.Log(context);
    }
}

Is there a way to log the Web API Request body so I can view it on the Application Insights dashboard on the Azure Portal? 有没有方法可以记录Web API请求主体,以便我可以在Azure门户的Application Insights仪表板上查看它?

You can create ExceptionTelemetry instance and add custom properties. 您可以创建ExceptionTelemetry实例并添加自定义属性。 Then call general Track method. 然后调用常规的Track方法。

var telemetry = new ExceptionTelemetry(context.Exception);
telemetry.Properties.Add("name", "value");
new TelemetryClient().Track(telemetry);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ASP.Net MVC和Web Api的Application Insights实时指标 - Application Insights Live Metrics with ASP.Net MVC and Web Api ASP.NET MVC Web Api:服务器端的application / xml PUT请求主体为null - ASP.NET MVC Web Api: application/xml PUT request body is null on server side 在ASP.NET Web Api中获取请求正文 - Get body of request in ASP.NET Web Api Web API 未在 Application Insights 和 ASP.Net Core 中注册信息日志 - Web API doesn't register Information log in Application Insights and ASP .Net Core 如何在 ASP.NET Core 中使用请求正文丰富 App Insights ExceptionTelemetry - How to enrich App Insights ExceptionTelemetry with request body in ASP.NET Core 如何在 ASP.NET Core 5 Web API 中绑定来自请求主体的简单类型 - How can I bind simple type coming from body of the request in ASP.NET Core 5 Web API 如何在生产环境中禁用 Asp.Net Core web API 中的 400 Bad request 的消息正文? - how to disable 400 Bad request's message body in Asp.Net Core web API in production environment? 如何将 POST 请求正文中的有效 XML 提交到使用 XML 的 ASP.NET Core Web API? - How to submit valid XML in a POST request body to an ASP.NET Core Web API that consumes XML? 如何通过仅允许在 asp.net 核心 web Z8A35DA52ED1057271 的 Model 中分配的属性来验证请求正文 - How to Validate Request Body by allowing only attributes assigned in the Model of an asp.net core web api app 如何从 ASP.NET Web API ValueProvider 中的 HTTP POST 请求检索正文值? - How do I retrieve body values from an HTTP POST request in an ASP.NET Web API ValueProvider?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM