From de72fe4fb9ffa0821a9751bf6ffaf6ef7764bd35 Mon Sep 17 00:00:00 2001
From: Jonnern <10881387+Jonnern@users.noreply.github.com>
Date: Fri, 22 Mar 2024 16:39:32 +0100
Subject: [PATCH] Implement high-performance logging (#193)
* Implement high-performance logging
---
.../Clients/BaseSocketClient.cs | 5 +-
CryptoExchange.Net/Clients/RestApiClient.cs | 17 +-
CryptoExchange.Net/Clients/SocketApiClient.cs | 38 +-
...ExchangeWebSocketClientLoggingExtension.cs | 348 ++++++++++++++++++
.../RestApiClientLoggingExtensions.cs | 81 ++++
.../SocketApiClientLoggingExtension.cs | 188 ++++++++++
.../SocketConnectionLoggingExtension.cs | 325 ++++++++++++++++
.../SymbolOrderBookLoggingExtensions.cs | 236 ++++++++++++
.../OrderBook/SymbolOrderBook.cs | 41 ++-
.../Sockets/CryptoExchangeWebSocketClient.cs | 61 +--
.../Sockets/SocketConnection.cs | 65 ++--
11 files changed, 1293 insertions(+), 112 deletions(-)
create mode 100644 CryptoExchange.Net/Logging/Extensions/CryptoExchangeWebSocketClientLoggingExtension.cs
create mode 100644 CryptoExchange.Net/Logging/Extensions/RestApiClientLoggingExtensions.cs
create mode 100644 CryptoExchange.Net/Logging/Extensions/SocketApiClientLoggingExtension.cs
create mode 100644 CryptoExchange.Net/Logging/Extensions/SocketConnectionLoggingExtension.cs
create mode 100644 CryptoExchange.Net/Logging/Extensions/SymbolOrderBookLoggingExtensions.cs
diff --git a/CryptoExchange.Net/Clients/BaseSocketClient.cs b/CryptoExchange.Net/Clients/BaseSocketClient.cs
index 0186956e..c913a338 100644
--- a/CryptoExchange.Net/Clients/BaseSocketClient.cs
+++ b/CryptoExchange.Net/Clients/BaseSocketClient.cs
@@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using CryptoExchange.Net.Interfaces;
+using CryptoExchange.Net.Logging.Extensions;
using CryptoExchange.Net.Objects.Sockets;
using Microsoft.Extensions.Logging;
@@ -63,7 +64,7 @@ public virtual async Task UnsubscribeAsync(UpdateSubscription subscription)
if (subscription == null)
throw new ArgumentNullException(nameof(subscription));
- _logger.Log(LogLevel.Information, $"Socket {subscription.SocketId} Unsubscribing subscription " + subscription.Id);
+ _logger.UnsubscribingSubscription(subscription.SocketId, subscription.Id);
await subscription.CloseAsync().ConfigureAwait(false);
}
@@ -86,7 +87,7 @@ public virtual async Task UnsubscribeAllAsync()
///
public virtual async Task ReconnectAsync()
{
- _logger.Log(LogLevel.Information, $"Reconnecting all {CurrentConnections} connections");
+ _logger.ReconnectingAllConnections(CurrentConnections);
var tasks = new List();
foreach (var client in ApiClients.OfType())
{
diff --git a/CryptoExchange.Net/Clients/RestApiClient.cs b/CryptoExchange.Net/Clients/RestApiClient.cs
index 59251b67..7bc09156 100644
--- a/CryptoExchange.Net/Clients/RestApiClient.cs
+++ b/CryptoExchange.Net/Clients/RestApiClient.cs
@@ -10,6 +10,7 @@
using System.Threading.Tasks;
using CryptoExchange.Net.Converters.JsonNet;
using CryptoExchange.Net.Interfaces;
+using CryptoExchange.Net.Logging.Extensions;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Objects.Options;
using CryptoExchange.Net.Requests;
@@ -152,9 +153,9 @@ protected virtual async Task SendRequestAsync(
var result = await GetResponseAsync