feat(telegram): configure deploy status and error level logging notification via Telegram API
Deploy to Production / Build Release Package (push) Failing after 19s
WBS-9.3 - NULL Policy CI Gate / NULL Policy Validation (push) Failing after 5s
Deploy to Production / Deploy to Production Server (push) Has been skipped
Deploy to Production / Post-Deployment Checks (push) Has been skipped
Snapshot Admin Deployment / build-and-deploy (push) Failing after 37s
Quant Engine CI/CD Pipeline / validate-core (push) Failing after 2m18s
Quant Engine CI/CD Pipeline / validate-ui-and-storage (push) Has been skipped

This commit is contained in:
2026-06-29 11:11:44 +09:00
parent c888486635
commit d7e937e67c
4 changed files with 80 additions and 26 deletions
@@ -0,0 +1,56 @@
using Serilog.Core;
using Serilog.Events;
using System.Net.Http;
using System.Text;
using System.Text.Json;
namespace QuantEngine.Web.Infrastructure
{
public class TelegramSink : ILogEventSink
{
private readonly string _botToken;
private readonly string _chatId;
private static readonly HttpClient HttpClient = new HttpClient();
public TelegramSink(string botToken, string chatId)
{
_botToken = botToken;
_chatId = chatId;
}
public void Emit(LogEvent logEvent)
{
if (logEvent.Level >= LogEventLevel.Error)
{
var sb = new StringBuilder();
sb.AppendLine("🚨 **QuantEngine Error Log**");
sb.AppendLine($"• Timestamp: {logEvent.Timestamp:yyyy-MM-dd HH:mm:ss}");
sb.AppendLine($"• Level: {logEvent.Level}");
sb.AppendLine($"• Message: {logEvent.RenderMessage()}");
if (logEvent.Exception != null)
{
sb.AppendLine($"• Exception: {logEvent.Exception.Message}");
}
try
{
var payload = new
{
chat_id = _chatId,
text = sb.ToString(),
parse_mode = "Markdown"
};
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
// Fire and forget to avoid blocking main execution threads
_ = HttpClient.PostAsync($"https://api.telegram.org/bot{_botToken}/sendMessage", content);
}
catch
{
// Fallback to avoid crash loops inside logger
}
}
}
}
}