add: integrate Serilog for enhanced logging and monitoring

This commit is contained in:
2025-12-31 19:06:56 +03:30
parent 9b6c0d4cc4
commit fb62523a23
3 changed files with 47 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace _0_Framework.Application.PaymentGateway;
@@ -12,9 +13,11 @@ public class SepehrPaymentGateway:IPaymentGateway
{
private readonly HttpClient _httpClient;
private const long TerminalId = 99213700;
private readonly ILogger<SepehrPaymentGateway> _logger;
public SepehrPaymentGateway(IHttpClientFactory httpClient)
public SepehrPaymentGateway(IHttpClientFactory httpClient, ILogger<SepehrPaymentGateway> logger)
{
_logger = logger;
_httpClient = httpClient.CreateClient();
_httpClient.BaseAddress = new Uri("https://sepehr.shaparak.ir/Rest/V1/PeymentApi/");
}
@@ -35,6 +38,7 @@ public class SepehrPaymentGateway:IPaymentGateway
// خواندن محتوای پاسخ
var content = await res.Content.ReadAsStringAsync(cancellationToken);
// تبدیل پاسخ JSON به آبجکت دات‌نت
var json = System.Text.Json.JsonDocument.Parse(content);
@@ -46,7 +50,7 @@ public class SepehrPaymentGateway:IPaymentGateway
{
Status = status,
IsSuccess = status == "0",
Token = accessToken
Token = accessToken,
};
}
@@ -63,7 +67,9 @@ public class SepehrPaymentGateway:IPaymentGateway
// خواندن محتوای پاسخ
var content = await res.Content.ReadAsStringAsync(cancellationToken);
_logger.LogInformation(content);
// تبدیل پاسخ JSON به آبجکت دات‌نت
var json = System.Text.Json.JsonDocument.Parse(content);