DEV Community

Satish Patil
Satish Patil

Posted on β€’ Edited on

πŸš€ RootAlert - Real-time Exception Tracking & Alerting for .NET on Slack & Teams

NuGet Badge

πŸ” 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
Enter fullscreen mode Exit fullscreen mode

Or via Package Manager:

 Install-Package RootAlert
Enter fullscreen mode Exit fullscreen mode

⚑ 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();
Enter fullscreen mode Exit fullscreen mode

βœ… 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
Enter fullscreen mode Exit fullscreen mode
using RootAlert.Redis;
var rootAlertSetting = new RootAlertSetting
{
    Storage = new RedisAlertStorage("127.0.0.1:6379"),
    BatchInterval = TimeSpan.FromSeconds(20),
    RootAlertOptions = rootAlertOptions,
};
Enter fullscreen mode Exit fullscreen mode

βœ… Ideal for distributed apps running on multiple servers!

πŸ›  Using MSSQL for Storage

 dotnet add package RootAlert.MSSQL
Enter fullscreen mode Exit fullscreen mode
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,
};
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ 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()
);
Enter fullscreen mode Exit fullscreen mode

πŸ”— 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:

  1. Open Microsoft Teams, go to the desired channel.
  2. Click β€œβ€¦β€ (More options) β†’ Connectors.
  3. Select β€œIncoming Webhook”, configure it, and copy the Webhook URL.
  4. Add it to RootAlertOptions in your Program.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:

Teams Workflow API Setup


πŸ’¬ 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)
----------------------------------------------------
Enter fullscreen mode Exit fullscreen mode

🎯 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! 😊

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay