add: integrate Serilog for enhanced logging and monitoring
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ using GozareshgirProgramManager.Application.Modules.Users.Commands.CreateUser;
|
||||
using GozareshgirProgramManager.Infrastructure;
|
||||
using GozareshgirProgramManager.Infrastructure.Persistence.Seed;
|
||||
using Microsoft.OpenApi;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using ServiceHost.Hubs.ProgramManager;
|
||||
using ServiceHost.Notifications.ProgramManager;
|
||||
using ServiceHost.Conventions;
|
||||
@@ -53,7 +55,36 @@ builder.Services.AddHttpClient("holidayApi", c => c.BaseAddress = new System.Uri
|
||||
var connectionString = builder.Configuration.GetConnectionString("MesbahDb");
|
||||
var connectionStringTestDb = builder.Configuration.GetConnectionString("TestDb");
|
||||
|
||||
#region Serilog
|
||||
var logDirectory = @"C:\Logs\Gozareshgir\";
|
||||
|
||||
if (!Directory.Exists(logDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(logDirectory);
|
||||
}
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
//NO EF Core log
|
||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
|
||||
|
||||
//NO DbCommand log
|
||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
|
||||
|
||||
//NO Microsoft Public log
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
||||
//.MinimumLevel.Information()
|
||||
.WriteTo.File(
|
||||
path: Path.Combine(logDirectory, "gozareshgir_log.txt"),
|
||||
rollingInterval: RollingInterval.Day,
|
||||
retainedFileCountLimit: 30,
|
||||
shared: true,
|
||||
outputTemplate:
|
||||
"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"
|
||||
).CreateLogger();
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
builder.Services.AddProgramManagerApplication();
|
||||
builder.Services.AddProgramManagerInfrastructure(builder.Configuration);
|
||||
@@ -348,7 +379,8 @@ builder.Services.AddParbad().ConfigureGateways(gateways =>
|
||||
});
|
||||
|
||||
|
||||
|
||||
builder.Host.UseSerilog();
|
||||
Log.Information("SERILOG STARTED SUCCESSFULLY");
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors("AllowSpecificOrigins");
|
||||
|
||||
@@ -94,11 +94,16 @@
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.5.2" />
|
||||
<PackageReference Include="Parbad.AspNetCore" Version="1.5.0" />
|
||||
<PackageReference Include="Parbad.Storage.Cache" Version="1.5.0" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="SocialExplorer.FastDBF" Version="1.0.0" />
|
||||
<PackageReference Include="System.Data.OleDb" Version="10.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Storage\Task\" />
|
||||
|
||||
Reference in New Issue
Block a user