🚀 RootAlert - Real-time Exception Tracking for .NET
RootAlert is an open-source real-time error tracking and alerting library for .NET applications. It captures unhandled exceptions, batches them intelligently, and sends alerts to Microsoft Teams, Slack, and more.
🔥 Features
✅ Automatic exception tracking with minimal setup
✅ Batched alerts to prevent spam
✅ Microsoft Teams (Adaptive Cards) & Slack (Blocks & Sections) support
✅ Customizable batch interval using TimeSpan
✅ Supports Redis-based storage for persistence
✅ Rich error logs including request details, headers, and stack traces
📦 Installation
RootAlert is available on NuGet. Install it using:
dotnet add package RootAlert --version 0.1.5
Or via Package Manager:
Install-Package RootAlert -Version 0.1.5
⚡ Quick Start
1️⃣ Configure RootAlert in Program.cs
Register RootAlert and configure your preferred alerting method (Teams, Slack, etc.).
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
{
Storage = new RedisAlertStorage("127.0.0.1:6379"), // Redis storage
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();
✅ RootAlert will now automatically capture all unhandled exceptions!
🚀 Redis Storage for Persistent Logging
By default, RootAlert batches errors in memory, meaning errors are lost if the application restarts. To ensure persistence, you can use Redis as storage.
** 1️⃣ Configure Redis Storage in Program.cs
**
Update your RootAlertSetting to use Redis:
var rootAlertSetting = new RootAlertSetting
{
Storage = new RedisAlertStorage("127.0.0.1:6379"), // Use Redis storage
BatchInterval = TimeSpan.FromSeconds(20),
RootAlertOptions = rootAlertOptions,
};
2️⃣ Redis Benefits
✅ Persistence - Logs are stored even after an app restart.
✅ Scalability - Works across multiple instances of your app.
✅ Performance - Faster retrieval and processing of batched errors.
⚠️ Important Notes
❗ If an exception filter is added, RootAlert won't work.
Why? 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.
app.UseMiddleware<ExceptionHandlingMiddleware>(); // Your existing middleware
app.UseRootAlert(); // Register RootAlert after the exception middleware
🏆 Microsoft Teams Integration
RootAlert supports Microsoft Teams via Adaptive Cards for structured error logging.
🔹 How to Get a Teams Webhook URL
RootAlert supports Microsoft Teams integration via:
- Incoming Webhooks (Connector) – Simple and quick setup. (Will be deprecated)
- 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
- Open Microsoft Teams and go to the desired channel.
- Click "…" (More options) → Connectors.
- Find "Incoming Webhook" and click "Configure".
- Name it RootAlert Notifications and click Create.
- Copy the Webhook URL and use it in
RootAlertOptions
.
🔹 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:
🔗 YouTube Link: https://www.youtube.com/watch?v=jHTU_jUnswY
📌 Steps to Configure Teams Workflow API
-
Open Microsoft Teams and Go to Workflows
- Click on “…” (More options) → Workflows. --> Create
-
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.
-
Choose Team and Channel
- Select the Team where you want to post alerts.
- Choose the Channel where notifications should appear.
🔹 Example Teams Alert (Adaptive Card)
RootAlert sends alerts as rich Adaptive Cards:
-
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.
🚨 Example Error Alert
RootAlert captures rich error details including request details, headers, and stack traces:
🆔 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()
----------------------------------------------------
🛠 Roadmap
🔹 Database Storage - Store logs in SQL, Redis, or NoSQL
🔹 Email Alerts - Send exception reports via SMTP
🔹 Log Severity Filtering - Send only critical errors
📜 License
RootAlert is open-source and available under the MIT License.
💡 Contributing
🚀 Contributions are welcome! Feel free to submit pull requests or feature requests on GitHub.
🔗 Connect with Us
📧 Email: satsvelke@gmail.com
🐦 Twitter: @satsvelke
Top comments (0)