Skip to content

Logging

Oddbjørn Bakke edited this page May 17, 2021 · 2 revisions

Getting logs from the SDK

The SDK uses ILogger/ILoggerFactory abstractions, you might set this or not use it at all.
But if you want logs, you will need to provide some logger to the SDK with this abstraction.

  • Add the serviceCollection.AddTouchPortalSdk(configurationRoot); and the resolve through ITouchPortalClientFactory.
  • Or provide and ILoggerFactory interface on the TouchPortalFactory, ex. TouchPortalFactory.CreateClient(this, loggerFactory: loggerFactory);
public class SamplePlugin
{
    string ITouchPortalEventHandler.PluginId => "Sample.Plugin";
    
    private readonly ITouchPortalClient _client;
    
    public SamplePlugin(ITouchPortalClientFactory touchPortalClientFactory)
    {
        //This factory needs 'serviceCollection.AddTouchPortalSdk(configurationRoot);' to work:
        _client = touchPortalClientFactory.CreateClient(this)
        //or:
        _client = TouchPortalFactory.CreateClient(this, loggerFactory: loggerFactory);
    }
}

Configure loglevel

If the log contains to much noise from the SDK, add the TouchPortalSDK section with Warning or Error level.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "TouchPortalSDK" : "Warning"
    }
  }
}
Clone this wiki locally