feat: integrate Serilog and Telegram notifications
TaxBaik CI/CD / build-and-deploy (push) Successful in 51s
TaxBaik CI/CD / build-and-deploy (push) Successful in 51s
- Add Serilog for structured logging (Console + File) - Implement TelegramNotificationService for admin alerts - Log successful/failed login attempts with Telegram notifications - Add application startup/shutdown logging - Log important events to Telegram Chat ID: -5585148480 - Configuration: Telegram:BotToken and Telegram:ChatId in appsettings Features: - Automatic daily log rotation - Structured logging with timestamps - Environment-aware alerts - Error and info level Telegram messages Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Application.DTOs;
|
||||
using TaxBaik.Domain.Entities;
|
||||
@@ -17,17 +18,28 @@ public class AnnouncementBrowserClient : IAnnouncementBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<AnnouncementBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public AnnouncementBrowserClient(HttpClient http, ILogger<AnnouncementBrowserClient> logger)
|
||||
public AnnouncementBrowserClient(HttpClient http, ILogger<AnnouncementBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken) && !_http.DefaultRequestHeaders.Contains("Authorization"))
|
||||
{
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Announcement>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<AnnouncementListResponse>("announcement", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
@@ -42,6 +54,7 @@ public class AnnouncementBrowserClient : IAnnouncementBrowserClient
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<Announcement>($"announcement/{id}", cancellationToken: ct);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
@@ -55,6 +68,7 @@ public class AnnouncementBrowserClient : IAnnouncementBrowserClient
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("announcement", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
@@ -74,6 +88,7 @@ public class AnnouncementBrowserClient : IAnnouncementBrowserClient
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"announcement/{id}", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
@@ -93,6 +108,7 @@ public class AnnouncementBrowserClient : IAnnouncementBrowserClient
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"announcement/{id}", cancellationToken: ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user