DEV Community

Satish Patil
Satish Patil

Posted 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.3
Enter fullscreen mode Exit fullscreen mode

Or via Package Manager:

 Install-Package RootAlert -Version 0.1.3
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<RootAlertOptions>
{
    new RootAlertOptions
    {
        AlertMethod = AlertType.Teams,
        WebhookUrl = "https://your-teams-webhook-url",
        BatchInterval = TimeSpan.FromMinutes(1)
    },
    new RootAlertOptions
    {
        AlertMethod = AlertType.Slack,
        WebhookUrl = "https://your-slack-webhook-url",
        BatchInterval = TimeSpan.FromMinutes(1)
    }
};

builder.Services.AddRootAlert(rootAlertOptions);

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

🔹 How to Set Up a Teams Webhook

  1. Open Microsoft Teams and go to your channel.
  2. Click "..." → Connectors.
  3. Select Incoming Webhook, click Configure.
  4. Name it RootAlert Notifications and click Create.
  5. Copy the Webhook URL and paste it in RootAlertOptions.

🔹 Example Teams Alert (Adaptive Card Format)

RootAlert sends alerts as rich Adaptive Cards:

Teams Adaptive Card


💬 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 SQL, Redis, or NoSQL.

Email Alerts via SMTP - Get notifications in your inbox.

Severity Filtering - Customize alerts based on error level.


Top comments (0)