2025-07-17 09:22:55 -04:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2025-06-25 13:01:32 -04:00
|
|
|
|
using Serilog;
|
2025-07-02 11:37:41 -04:00
|
|
|
|
using Shared.DTO.VariablesEntorno;
|
2025-06-25 13:01:32 -04:00
|
|
|
|
|
|
|
|
|
namespace Shared.Helper
|
|
|
|
|
{
|
2025-07-01 14:00:41 -04:00
|
|
|
|
public class FileLoggerHelper
|
2025-06-25 13:01:32 -04:00
|
|
|
|
{
|
2025-07-01 14:00:41 -04:00
|
|
|
|
public static void ConfigureLogger(IConfiguration configuration)
|
|
|
|
|
{
|
2025-07-16 20:39:24 -04:00
|
|
|
|
var logFilePath = configuration.GetSection("Logging:LogFile:Path").Value ?? "";
|
2025-07-01 14:00:41 -04:00
|
|
|
|
var logFileFullPath = Path.Combine(Directory.GetCurrentDirectory(), logFilePath);
|
2025-06-25 13:01:32 -04:00
|
|
|
|
|
2025-07-01 14:00:41 -04:00
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
|
.ReadFrom.Configuration(configuration)
|
|
|
|
|
.WriteTo.File(logFileFullPath, rollingInterval: RollingInterval.Day)
|
|
|
|
|
.CreateLogger();
|
|
|
|
|
}
|
2025-06-25 13:01:32 -04:00
|
|
|
|
|
2025-07-01 14:00:41 -04:00
|
|
|
|
public static void LogInformation(string message)
|
|
|
|
|
{
|
|
|
|
|
Log.Information($"{message}");
|
|
|
|
|
}
|
2025-06-25 13:01:32 -04:00
|
|
|
|
|
2025-07-01 14:00:41 -04:00
|
|
|
|
public static void LogError(string message, Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(ex, message);
|
|
|
|
|
}
|
2025-06-25 13:01:32 -04:00
|
|
|
|
}
|
|
|
|
|
}
|