Initial commit.

This commit is contained in:
Burak Kaan Köse
2024-04-18 01:44:37 +02:00
parent 524ea4c0e1
commit 12d3814626
671 changed files with 77295 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
using System.IO;
using Serilog;
using Serilog.Core;
using Serilog.Exceptions;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.Services
{
public class LogInitializer : ILogInitializer
{
public const string WinoLogFileName = "WinoDiagnostics.log";
private readonly LoggingLevelSwitch _levelSwitch = new LoggingLevelSwitch();
private readonly IPreferencesService _preferencesService;
public LogInitializer(IPreferencesService preferencesService)
{
_preferencesService = preferencesService;
RefreshLoggingLevel();
}
public void RefreshLoggingLevel()
{
_levelSwitch.MinimumLevel = _preferencesService.IsLoggingEnabled ? Serilog.Events.LogEventLevel.Debug : Serilog.Events.LogEventLevel.Fatal;
}
public void SetupLogger(string logFolderPath)
{
string logFilePath = Path.Combine(logFolderPath, WinoLogFileName);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(_levelSwitch)
.WriteTo.File(logFilePath)
.WriteTo.Debug()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.CreateLogger();
}
}
}