Update logging with StoreHandler name

This commit is contained in:
erri120 2021-07-16 14:17:06 +02:00
parent d64afea6ab
commit 1f1340f921
No known key found for this signature in database
GPG Key ID: 7FA9556C936B847C

View File

@ -14,16 +14,15 @@ namespace Wabbajack.Common.StoreHandlers
{
public class StoreHandler
{
private static readonly StoreHandlerLogger Logger = new();
private static readonly Lazy<StoreHandler> _instance = new(() => new StoreHandler(), isThreadSafe: true);
public static StoreHandler Instance => _instance.Value;
private static readonly Lazy<SteamHandler> SteamHandler = new(() => new SteamHandler(Logger));
private static readonly Lazy<GOGHandler> GogHandler = new(() => new GOGHandler(Logger));
private static readonly Lazy<BethNetHandler> BethNetHandler = new(() => new BethNetHandler(Logger));
private static readonly Lazy<EGSHandler> EpicGameStoreHandler = new(() => new EGSHandler(Logger));
private static readonly Lazy<OriginHandler> OriginHandler = new(() => new OriginHandler(true, true, Logger));
private static readonly Lazy<SteamHandler> SteamHandler = new(() => new SteamHandler(new StoreHandlerLogger("Steam")));
private static readonly Lazy<GOGHandler> GogHandler = new(() => new GOGHandler(new StoreHandlerLogger("GOG")));
private static readonly Lazy<BethNetHandler> BethNetHandler = new(() => new BethNetHandler(new StoreHandlerLogger("BethNet")));
private static readonly Lazy<EGSHandler> EpicGameStoreHandler = new(() => new EGSHandler(new StoreHandlerLogger("EGS")));
private static readonly Lazy<OriginHandler> OriginHandler = new(() => new OriginHandler(true, true, new StoreHandlerLogger("Origin")));
private readonly List<AStoreGame> _storeGames;
public Dictionary<Game, AStoreGame> Games = new();
@ -100,9 +99,16 @@ namespace Wabbajack.Common.StoreHandlers
internal class StoreHandlerLogger : ILogger
{
private readonly string _name;
public StoreHandlerLogger(string name)
{
_name = name;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Utils.Log(formatter(state, exception));
Utils.Log($"{_name}: {formatter(state, exception)}");
}
public bool IsEnabled(LogLevel logLevel) => true;