29 lines
878 B
C#
29 lines
878 B
C#
using Microsoft.Extensions.Configuration;
|
|
using Serilog;
|
|
|
|
namespace Shared.Helper
|
|
{
|
|
public class FileLoggerHelper
|
|
{
|
|
public static void ConfigureLogger(IConfiguration configuration)
|
|
{
|
|
var logFilePath = configuration.GetSection("Logging:LogFile:Path").Value;
|
|
var logFileFullPath = Path.Combine(Directory.GetCurrentDirectory(), logFilePath);
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
.ReadFrom.Configuration(configuration)
|
|
.WriteTo.File(logFileFullPath, rollingInterval: RollingInterval.Day)
|
|
.CreateLogger();
|
|
}
|
|
|
|
public static void LogInformation(string message)
|
|
{
|
|
Log.Information($"{message}");
|
|
}
|
|
|
|
public static void LogError(string message, Exception ex)
|
|
{
|
|
Log.Error(ex, message);
|
|
}
|
|
}
|
|
}
|