C# 如何将ASP.NET Web API请求主体记录到应用程序中?
我正在使用TelemetryClient将未处理的异常记录在ExceptionLogger中,以查看Azure上的应用程序洞察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
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()的操作代码>