Browse Source

Updated RPC and Webhooks to use the new serializer events

voice-allocs
RogueException 7 years ago
parent
commit
b6b0a4dbbd
2 changed files with 18 additions and 6 deletions
  1. +9
    -3
      src/Discord.Net.Rpc/DiscordRpcClient.cs
  2. +9
    -3
      src/Discord.Net.Webhook/DiscordWebhookClient.cs

+ 9
- 3
src/Discord.Net.Rpc/DiscordRpcClient.cs View File

@@ -39,10 +39,16 @@ namespace Discord.Rpc
_rpcLogger = LogManager.CreateLogger("RPC");

_serializer = DiscordRpcJsonSerializer.Global.CreateScope();
_serializer.Error += ex =>
if (config.LogLevel >= LogSeverity.Warning)
{
_rpcLogger.WarningAsync("Serializer Error", ex).GetAwaiter().GetResult();
};
_serializer.ModelError += (path, ex)
=> _rpcLogger.WarningAsync($"Failed to deserialize {path}", ex).GetAwaiter().GetResult();
}
if (config.LogLevel >= LogSeverity.Debug)
{
_serializer.UnmappedProperty += path
=> _rpcLogger.DebugAsync($"Unmapped property: {path}");
}

SetApiClient(new API.DiscordRpcApiClient(clientId, DiscordRestConfig.UserAgent, origin, config.RestClientProvider, config.WebSocketProvider, _serializer));
ApiClient.SentRpcMessage += async opCode => await _rpcLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false);


+ 9
- 3
src/Discord.Net.Webhook/DiscordWebhookClient.cs View File

@@ -31,10 +31,16 @@ namespace Discord.Webhook
_webhookId = webhookId;

_serializer = DiscordRestJsonSerializer.Global.CreateScope();
_serializer.Error += ex =>
if (config.LogLevel >= LogSeverity.Warning)
{
_restLogger.WarningAsync("Serializer Error", ex).GetAwaiter().GetResult();
};
_serializer.ModelError += (path, ex)
=> _restLogger.WarningAsync($"Failed to deserialize {path}", ex).GetAwaiter().GetResult();
}
if (config.LogLevel >= LogSeverity.Debug)
{
_serializer.UnmappedProperty += path
=> _restLogger.DebugAsync($"Unmapped property: {path}");
}

ApiClient = new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, _serializer);
LogManager = new LogManager(config.LogLevel);


Loading…
Cancel
Save