π Tired of missing critical exceptions in your .NET apps? Meet RootAlert β a lightweight, real-time error tracking library that captures unhandled exceptions, batches them intelligently, and alerts your team via Microsoft Teams and Slack.
π₯ Key Features
β
Automatic exception handling via middleware
β
Real-time alerts with batching to prevent spam
β
Supports Microsoft Teams (Adaptive Cards) & Slack (Blocks & Sections)
β
Configurable batch interval using TimeSpan
β
Rich error logs including request details, headers, and stack traces
β
Supports Redis & MSSQL for persistent storage
π¦ Installation
Install RootAlert from NuGet:
dotnet add package RootAlert
Or via Package Manager:
Install-Package RootAlert
β‘ Quick Start
1οΈβ£ Configure RootAlert in Program.cs
using RootAlert.Config; using RootAlert.Extensions; using RootAlert.Storage; var builder = WebApplication.CreateBuilder(args); var rootAlertOptions = new List<RootAlertOption> { new RootAlertOption { AlertMethod = AlertType.Teams, WebhookUrl = "https://your-teams-webhook-url" }, new RootAlertOption { AlertMethod = AlertType.Slack, WebhookUrl = "https://your-slack-webhook-url" } }; var rootAlertSetting = new RootAlertSetting { BatchInterval = TimeSpan.FromSeconds(20), RootAlertOptions = rootAlertOptions, }; builder.Services.AddRootAlert(rootAlertSetting); var app = builder.Build(); app.UseMiddleware<ExceptionHandlingMiddleware>(); app.UseRootAlert(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.Run();
β Now, RootAlert will automatically capture all unhandled exceptions!
π‘ Persistent Storage Options (Redis & MSSQL)
RootAlert supports external storage:
- πΉ RootAlert.Redis β Stores logs in Redis
- πΉ RootAlert.MSSQL β Stores logs in SQL Server
π Using Redis for Storage
dotnet add package RootAlert.Redis
using RootAlert.Redis; var rootAlertSetting = new RootAlertSetting { Storage = new RedisAlertStorage("127.0.0.1:6379"), BatchInterval = TimeSpan.FromSeconds(20), RootAlertOptions = rootAlertOptions, };
β Ideal for distributed apps running on multiple servers!
π Using MSSQL for Storage
dotnet add package RootAlert.MSSQL
using RootAlert.MSSQL; var rootAlertSetting = new RootAlertSetting { Storage = new MSSQLAlertStorage("Server=myServer;Database=myDB;User Id=myUser;Password=myPassword;"), BatchInterval = TimeSpan.FromSeconds(20), RootAlertOptions = rootAlertOptions, };
π SQL Table Schema for MSSQL:
CREATE TABLE RootAlertLogs ( Id INT IDENTITY PRIMARY KEY, ExceptionMessage NVARCHAR(MAX) NOT NULL, StackTrace NVARCHAR(MAX) NULL, RequestUrl NVARCHAR(MAX) NULL, HttpMethod NVARCHAR(10) NULL, Headers NVARCHAR(MAX) NULL, CreatedAt DATETIME2 DEFAULT GETUTCDATE() );
π Microsoft Teams Integration
RootAlert supports Microsoft Teams via:
1οΈβ£ Incoming Webhooks (Connector) - Simple & Quick Setup.
2οΈβ£ Microsoft Teams Workflow API - Easier than Power Automate.
π Steps to Configure Teams Webhook:
- Open Microsoft Teams, go to the desired channel.
- Click ββ¦β (More options) β Connectors.
- Select βIncoming Webhookβ, configure it, and copy the Webhook URL.
- Add it to
RootAlertOptions
in yourProgram.cs
.
π Using Microsoft Teams Workflow API:
- Open Teams β ββ¦β β Workflows β Select "Post to a channel when a webhook request is received" template.
- Set up the webhook & use the URL in RootAlert.
π₯ Watch a step-by-step guide here:
π¬ Slack Integration
1οΈβ£ Go to Slack API & create a new Slack App.
2οΈβ£ Enable Incoming Webhooks under Features.
3οΈβ£ Click "Add New Webhook to Workspace" & select a channel.
4οΈβ£ Copy the Webhook URL & use it in RootAlertOptions
.
β Structured Slack alerts using Blocks & Sections for clear error logs.
π Example Batched Error Summary Alert
π¨ Root Alert - Batched Error Summary π΄ Error #1 Error Count: 3 π
Timestamp: 03/22/2025 6:30:29 PM π Request URL: /getuser π‘ HTTP Method: GET π© Headers: Accept: application/json ---------------------------------------------------- β οΈ Exception Details β Type: HttpRequestException π¬ Message: Weather API failed to respond ---------------------------------------------------- π Stack Trace at WeatherService.GetWeatherData() in WeatherService.cs:line 45 at RootAlertMiddleware.Invoke(HttpContext context) ----------------------------------------------------
π― Final Thoughts
RootAlert is open-source and designed for modern .NET applications to improve exception tracking and response time.
π Give it a try & let me know your feedback!
π NuGet: RootAlert
π» GitHub Repo: RootAlert on GitHub
Have questions? Drop them in the comments below! π
Top comments (0)