Monitor Exception ใน ASP.NET Core ด้วย Sentry

wk
1 min readApr 25, 2020

--

ขั้นตอน

  1. เพิ่มโปรเจคใน Sentry.io ชื่อ MyWeb

2. สร้าง WebAPI ผ่าน .NET CLI

$ dotnet new webapi --language C# --output src/MyWeb

3. ติดตั้ง Package Sentry.AspNetCore

$ dotnet add src/MyWeb package Sentry.AspNetCore

4. Integrate Sentry ด้วยฟังก์ชัน UseSentry() ในไฟล์ src/MyWeb/Program.cs

5. เพิ่ม Dsn ของ Sentry ในไฟล์ src/MyWeb/appsettings.json

6. เพิ่ม API src/MyWeb/Controllers/HelloController.cs

7. รันโปรแกรม

$ dotnet run --project src/MyWeb/MyWeb.csproj

8. ทดสอบ API ด้วย curl โดยส่ง name เป็นค่าว่างเพื่อให้เกิด Exception

$ curl http://localhost:5000/hello/sayHello?name=

9. ตรวจสอบที่ Sentry.io จะพบว่ามี 1 Issue ซึ่งเกิดจากการเรียก API sayHello

--

--

No responses yet