Files
ClubPenguinClient/MareSynchronos/Utils/DalamudLogger.cs
rootdarkarchon 2ae5d42e4d Loggerrework (#45)
* test some refactoring for cachedplayer

* rework logging

* fix saving of log level

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
2023-02-18 15:23:38 +01:00

39 lines
1.3 KiB
C#

using Dalamud.Logging;
using MareSynchronos.MareConfiguration;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.Utils;
internal class DalamudLogger : ILogger
{
private readonly string _name;
private readonly MareConfigService _mareConfigService;
public DalamudLogger(string name, MareConfigService mareConfigService)
{
this._name = name;
_mareConfigService = mareConfigService;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel)) return;
if (exception == null)
PluginLog.Information($"[{_name}]{{{(int)logLevel}}} {formatter(state, exception)}");
else if (logLevel == LogLevel.Warning)
PluginLog.Warning($"[{_name}]{{{(int)logLevel}}} {formatter(state, exception)}");
else if (logLevel == LogLevel.Error)
PluginLog.Error($"[{_name}]{{{(int)logLevel}}} {formatter(state, exception)}");
else
PluginLog.Fatal($"[{_name}]{{{(int)logLevel}}} {formatter(state, exception)}");
}
public bool IsEnabled(LogLevel logLevel)
{
return (int)_mareConfigService.Current.LogLevel <= (int)logLevel;
}
public IDisposable BeginScope<TState>(TState state) => default!;
}