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

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:

  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)
----------------------------------------------------

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