将Angular(6)客户端错误发送到Web API进行日志记录 [英] Send Angular (6) client side errors to web API for logging

查看:81
本文介绍了将Angular(6)客户端错误发送到Web API进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个人在这里没有回答就问了我确切的问题:角度2客户端错误

Another person asked my exact question here with no answer: Angular 2 Client Side Errors

我想要一种方法(如果可能的话,避免使用其他第三方框架),将客户端的Angular错误发送到后端异常记录器.

I'm wanting a way (avoiding additional third party frameworks if possible) to send my client-side Angular errors to my back end exception logger.

我的后端只是连接到我们的SQL Server数据库的.NET Web API项目.每当发生服务器错误时,我的服务器端错误就会通过调用存储过程控制器记录到数据库中(我使用KudVenKat的教程来构建此错误:

My back end is just a .NET Web API project that's connected to our SQL Server database. My server side errors are currently being logged to the database by calling a stored procedure controller whenever a server error occurs (I used KudVenKat's tutorial to build this: http://csharp-video-tutorials.blogspot.com/2012/12/logging-exception-to-database-part-75.html).

是否可以编写一种调用我的ErrorLogger API的Angular服务以将我的Angular错误记录到数据库中?

Is there a way to write an Angular service which calls my ErrorLogger API to log my Angular errors to the database?

我认为我可能不得不调整后端记录器控制器,因为它使用的是.NET的System.Exception类,我猜这仅对检测服务器端异常有效,而对Angular无效.我可能只需要客户端错误就需要一个完全不同的记录器控制器和数据库表-但我希望尽可能将服务器错误和客户端错误记录到同一张表中.

I figure I may have to tweak my back end logger controller since it's using .NET's System.Exception class, which I'm guessing is only good for detecting server side exceptions, not Angular's. I may need an entirely different logger controller and database table for client side errors only - but I'd like server and client side errors logged to the same table if possible.

知道这一点-我想做的甚至是一个好的方法吗?如果不是这样,谁能给我一个高级的描述,而不是如何记录这些客户端错误?

Knowing this - is what I'm trying to do even a good approach? If not, can anyone give me a high level description of how I might go about logging these client side errors instead?

推荐答案

Angular提供了用于处理错误的全局错误处理程序服务.

Angular provides global error handler service for handling the errors.

我们可以创建自己的自定义错误处理程序服务,以扩展ErrorHandler.

We can create our own custom error handler service which extends ErrorHandler .

在handleError方法中,您可以调用API并将客户端错误传递给服务器

In the handleError method you can call API and pass the client error to server

您可以引用 https://angular.io/api/core/ErrorHandler

这篇关于将Angular(6)客户端错误发送到Web API进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆