Implement ILogger abstraction for Playnite
parent
fe0bdf31f6
commit
ead2c9c3f1
|
@ -41,6 +41,9 @@
|
|||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Playnite.SDK, Version=6.10.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\PlayniteSDK.6.10.0\lib\net462\Playnite.SDK.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -104,6 +107,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions\MultiplayerInfoExtensions.cs" />
|
||||
<Compile Include="PlayniteLogger.cs" />
|
||||
<Compile Include="SaveController.cs" />
|
||||
<Compile Include="UninstallController.cs" />
|
||||
<Compile Include="InstallController.cs" />
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace LANCommander.PlaynitePlugin
|
|||
|
||||
Settings = new LANCommanderSettingsViewModel(this);
|
||||
|
||||
LANCommanderClient = new SDK.Client(Settings.ServerAddress);
|
||||
LANCommanderClient = new SDK.Client(Settings.ServerAddress, new PlayniteLogger(Logger));
|
||||
LANCommanderClient.UseToken(new SDK.Models.AuthToken()
|
||||
{
|
||||
AccessToken = Settings.AccessToken,
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LANCommander.PlaynitePlugin
|
||||
{
|
||||
public sealed class PlayniteLogger : ILogger
|
||||
{
|
||||
private readonly Playnite.SDK.ILogger Logger;
|
||||
|
||||
public PlayniteLogger(Playnite.SDK.ILogger logger) {
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
switch (logLevel)
|
||||
{
|
||||
case LogLevel.Trace:
|
||||
Logger?.Trace(formatter.Invoke(state, exception));
|
||||
break;
|
||||
|
||||
case LogLevel.Debug:
|
||||
Logger?.Debug(formatter.Invoke(state, exception));
|
||||
break;
|
||||
|
||||
case LogLevel.Information:
|
||||
Logger.Info(formatter.Invoke(state, exception));
|
||||
break;
|
||||
|
||||
case LogLevel.Warning:
|
||||
Logger.Warn(formatter.Invoke(state, exception));
|
||||
break;
|
||||
|
||||
case LogLevel.Error:
|
||||
case LogLevel.Critical:
|
||||
Logger.Error(formatter.Invoke(state, exception));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue