feat: Serilog Telegram Integration for Alert Notifications
Add automatic Telegram notifications for ERROR and FATAL level logs. Features: - TelegramSink: Custom Serilog sink for Telegram API integration - Conditional logging: Only ERROR and FATAL levels trigger alerts - Environment variables: TELEGRAM_BOT and CHAT_ID from Gitea Secrets - Non-blocking: Telegram failures don't crash application Configuration: - Reads TELEGRAM_BOT and CHAT_ID from environment - Formatted messages with emoji, timestamp, and exception details - Markdown parsing for better Telegram presentation This enables real-time alerting for critical issues during: - Gate 3 Shadow Run execution - Production deployments - System errors and exceptions Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ using KArtSell.BuildingBlocks.Capabilities;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using KArtSell.Host.Jobs;
|
||||
using KArtSell.Host.Configuration;
|
||||
using KArtSell.Host.Infrastructure;
|
||||
using KArtSell.BuildingBlocks.Data;
|
||||
using KArtSell.BuildingBlocks.Reliability;
|
||||
using KArtSell.BuildingBlocks.Time;
|
||||
@@ -18,14 +19,28 @@ using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Host.UseSerilog((context, services, logger) => logger
|
||||
.ReadFrom.Configuration(context.Configuration)
|
||||
.ReadFrom.Services(services)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console());
|
||||
// Load Telegram secrets for Serilog notifications
|
||||
var telegramBotToken = Environment.GetEnvironmentVariable("TELEGRAM_BOT") ?? string.Empty;
|
||||
var telegramChatId = Environment.GetEnvironmentVariable("CHAT_ID") ?? string.Empty;
|
||||
|
||||
builder.Host.UseSerilog((context, services, logger) =>
|
||||
{
|
||||
var config = logger
|
||||
.ReadFrom.Configuration(context.Configuration)
|
||||
.ReadFrom.Services(services)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console();
|
||||
|
||||
// Add Telegram sink for ERROR and FATAL logs
|
||||
if (!string.IsNullOrEmpty(telegramBotToken) && !string.IsNullOrEmpty(telegramChatId))
|
||||
{
|
||||
config = config.WriteTo.Sink(new TelegramSink(telegramBotToken, telegramChatId), LogEventLevel.Error);
|
||||
}
|
||||
});
|
||||
|
||||
// Load secrets from environment variables (set by CI/CD or user-secrets in dev)
|
||||
var connectionString = ResolveSecret(
|
||||
|
||||
Reference in New Issue
Block a user