Wo und wie können Ausnahmen für azure Application Insights auf globaler Ebene im .NET-Kernprojekt platziert werden? Ich habe App-Insights installiert und kann die Telemetrie in Azure verfolgen, aber Ausnahmen für fehlgeschlagene Anfragen fehlen..Net Core - Azure Application Insights, die keine Ausnahmen anzeigen
1
A
Antwort
0
Ein Ansatz wäre, benutzerdefinierte Middleware zu erstellen, die den Fehler abfangen und die Ausnahme an AppInsights senden würde.
using System;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
namespace Middleware
{
public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseHttpException(this IApplicationBuilder application)
{
return application.UseMiddleware<HttpExceptionMiddleware>();
}
}
public class HttpExceptionMiddleware
{
private readonly RequestDelegate _next;
public HttpExceptionMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await _next.Invoke(context);
}
catch (Exception ex)
{
var telemetryClient = new TelemetryClient();
telemetryClient.TrackException(ex);
//handle response codes and other operations here
}
}
}
}
Dann registrieren, die Middleware im Configure-Methode des Startup:
app.UseHttpException();
Verwandte Themen
- 1. .NET Core-Ausnahmen, die nicht in Application Insight verfolgt werden
- 2. Azure Application Insights protokolliert keine Redis-Aufrufe
- 3. Application Insights - Keine Daten für die Abhängigkeitsdauer
- 4. ASP.NET Core-Ablaufverfolgung, die auf Azure mit Application Insights protokolliert
- 5. Application Insights - Komponententests, Azure
- 6. Azure Application Insights
- 7. Application Insights - SQL Query anzeigen
- 8. Application Insights verfolgen keine SQL-Abfragen
- 9. Azure Application Insights HTTP-Abhängigkeitsverfolgung Problem
- 10. Ignoriere Endpunkte von Azure Application Insights
- 11. Application Insights TraceListener sammelt keine Spuren?
- 12. Log4Net mit Application Insights
- 13. Wie Ignoriere localhost auf Azure Application Insights
- 14. Azure Application Insights - HTTP-Fehler suchen?
- 15. Azure Application Insights kann Server Monitor Graph
- 16. Verwenden von Azure Application Insights mit Azure WebJob
- 17. Application Insights
- 18. Verfolgt Application Insights die Referrer-URL?
- 19. Application Insights schlaffe Integration
- 20. Unterstützt Microsoft Application Insights MVC 6 (.Net 5)
- 21. Application Insights Delay?
- 22. Funktioniert Application Insights mit CoreCLR?
- 23. Wie Verknüpfen von Ausnahmen zu Anforderungen in Application Insights auf Azure?
- 24. Application Insights Abhängigkeitstypen
- 25. Application Insights für SharePoint-Anwendung
- 26. Azure Application Insights Analytics-Abfrage für Unions- und Spaltenvergleich
- 27. Azure Web Application Insights "Server" Daten sind leer
- 28. Application Insights Logs Analyse
- 29. Azure Application Insights: Formatieren von Datumsangaben (und Zahlen)
- 30. Ich kann die ASP.NET Core-Webanwendung nicht mit Application Insights verbinden
u sicher, das funktioniert? Für mich gibt es immer noch keine Ausnahmen. müssen Sie es zuerst in die Pipeline oder nach benutzerdefinierten Fehlern oder? –