Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将ASP.NET Web API请求主体记录到应用程序中?_C#_Azure_Asp.net Web Api_Azure Application Insights_Telemetry - Fatal编程技术网

C# 如何将ASP.NET Web API请求主体记录到应用程序中?

C# 如何将ASP.NET Web API请求主体记录到应用程序中?,c#,azure,asp.net-web-api,azure-application-insights,telemetry,C#,Azure,Asp.net Web Api,Azure Application Insights,Telemetry,我正在使用TelemetryClient将未处理的异常记录在ExceptionLogger中,以查看Azure上的应用程序洞察 public class GlobalExceptionLogger : ExceptionLogger { public override void Log(ExceptionLoggerContext context) { if (context != null && context.Exception != null

我正在使用TelemetryClient将未处理的异常记录在ExceptionLogger中,以查看Azure上的应用程序洞察

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);
    }
}

是否有方法记录Web API请求正文,以便我可以在Azure门户上的Application Insights仪表板上查看它?

您可以创建ExceptionTeletry实例并添加自定义属性。然后调用通用跟踪方法

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

还有一个版本的
Track*
方法使用字典,因此您可以执行类似
newtelemetryclient()的操作