DEV Community

Satish Patil
Satish Patil

Posted on β€’ Edited on

RootAlert: Real-time Exception Tracking & Alerts for .NET!

πŸš€ RootAlert: Real-time Exception Tracking & Alerts for .NET!

RootAlert is a powerful, lightweight real-time error tracking and alerting library for .NET applications. Whether you're building a small API or a large-scale enterprise system, RootAlert helps you monitor unhandled exceptions and get instant alerts in Microsoft Teams, Slack, and (soon) Email!

RootAlert

πŸ”₯ Why Use RootAlert?

βœ… Automatically capture unhandled exceptions via middleware.

βœ… Batch alerts to prevent spam while still getting timely notifications.

βœ… Multi-service alerting – Send error notifications to Teams, Slack, and Email.

βœ… Customizable batch intervals – Choose when to receive grouped alerts.

βœ… Rich error logs with request details, headers, and stack traces.


πŸ“¦ Installation & Setup

NuGet Badge
RootAlert is available on NuGet:

 dotnet add package RootAlert --version 0.1.5
Enter fullscreen mode Exit fullscreen mode

Or via Package Manager:

 Install-Package RootAlert -Version 0.1.5
Enter fullscreen mode Exit fullscreen mode

1️⃣ Add RootAlert to Your .NET Project

In Program.cs, configure RootAlert with multiple alert destinations:

using RootAlert.Config;
using RootAlert.Extensions;

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

// βœ… Handle exceptions first
app.UseMiddleware<ExceptionHandlingMiddleware>();

// βœ… Then, log errors with RootAlert
app.UseRootAlert();

app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

app.Run();
Enter fullscreen mode Exit fullscreen mode

βœ… Now, RootAlert will capture all unhandled exceptions and send alerts to multiple services!


⚠️ Important Notes

❗ If an exception filter is added, RootAlert won't work.

Reason: Exception filters handle errors before middleware gets a chance to process them. Since RootAlert works as middleware, it will never see the exception if a filter catches it first.

βœ… Solution: Ensure RootAlert is added after any existing exception-handling middleware.

If your application has a global exception-handling middleware, register RootAlert after it to ensure exceptions are logged correctly. Example:

app.UseMiddleware<ExceptionHandlingMiddleware>(); // Your existing middleware
app.UseRootAlert(); // Register RootAlert after the exception middleware
Enter fullscreen mode Exit fullscreen mode

πŸ† Microsoft Teams Integration

RootAlert supports Microsoft Teams integration via:

  1. Incoming Webhooks (Connector) – Simple and quick setup. (Will be deprecated)
  2. Microsoft Teams Workflow API – Easier than Power Automate, with a built-in Webhook template.

πŸ”Ή Option 1: Using an Incoming Webhook (Connector)

This method is the easiest way to receive error alerts in a Teams channel.

πŸ“Œ Steps to Get a Teams Webhook URL

  1. Open Microsoft Teams and go to the desired channel.
  2. Click "…" (More options) β†’ Connectors.
  3. Find "Incoming Webhook" and click "Configure".
  4. Name it RootAlert Notifications and click Create.
  5. Copy the Webhook URL and use it in your RootAlert configuration.

πŸ”Ή Option 2: Using Microsoft Teams Workflow API (via Webhook Template)

This method is even easier than Power Automate and uses a built-in workflow to receive data via Webhook.

πŸŽ₯ Watch this video for a step-by-step guide:

Microsoft Teams Workflow API Setup

πŸ”— YouTube Link: https://www.youtube.com/watch?v=jHTU_jUnswY

πŸ“Œ Steps to Configure Teams Workflow API

  1. Open Microsoft Teams and Go to Workflows

    • Click on β€œβ€¦β€ (More options) β†’ Workflows. --> Create
  2. Select "Post to a channel when a webhook request is received" Template

    • Search for "Post to a channel when a webhook request is received" and select the ready-made template.
    • Click Next to proceed.
  3. Choose Team and Channel

    • Select the Team where you want to post alerts.
    • Choose the Channel where notifications should appear.
  4. Copy the Webhook URL

    • After selecting the Team and Channel, Teams will generate a Webhook URL.
    • Copy this URL and use it in your RootAlert settings.

πŸ’¬ Slack Integration

πŸ”Ή How to Set Up a Slack Webhook

  1. Go to https://api.slack.com/apps.
  2. Create a new Slack App β†’ Enable Incoming Webhooks.
  3. Click Add New Webhook to Workspace, choose a channel.
  4. Copy the Webhook URL and paste it in RootAlertOptions.

πŸ”Ή Example Slack Alert (Blocks & Sections Format)

RootAlert formats messages beautifully in Slack:

Slack Alert


🚨 Example Error Alert

This is how RootAlert captures errors and logs detailed request information:

πŸ†” Error ID: abc123
⏳ Timestamp: 02/05/2025 4:02:41 AM
----------------------------------------------------
🌐 REQUEST DETAILS
πŸ”— URL: /weatherforecast
πŸ“‘ HTTP Method: GET
----------------------------------------------------
πŸ“© REQUEST HEADERS
πŸ“ User-Agent: Mozilla/5.0
----------------------------------------------------
⚠️ EXCEPTION DETAILS
❗ Type: DivideByZeroException
πŸ’¬ Message: Attempted to divide by zero.
----------------------------------------------------
πŸ” STACK TRACE
   at Program.Main() in Program.cs:line 54
   at RootAlertMiddleware.Invoke()
----------------------------------------------------
Enter fullscreen mode Exit fullscreen mode

πŸ”œ Coming Soon!

βœ” Database Storage - Store logs in MSSQL and Postgres
For Redis ->> using storage with Redis
βœ” Email Alerts via SMTP - Get notifications in your inbox.

βœ” Severity Filtering - Customize alerts based on error level.


Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more