From 2da2bcf96ba8b46d24108b6fede144da064101ad Mon Sep 17 00:00:00 2001 From: Jkorf Date: Mon, 19 Apr 2021 11:07:48 +0200 Subject: [PATCH] Added extra debug messages --- CryptoExchange.Net/CryptoExchange.Net.xml | 145 ++++++++++++++++++ CryptoExchange.Net/SocketClient.cs | 11 ++ .../Sockets/SocketConnection.cs | 5 +- 3 files changed, 160 insertions(+), 1 deletion(-) diff --git a/CryptoExchange.Net/CryptoExchange.Net.xml b/CryptoExchange.Net/CryptoExchange.Net.xml index 86e733c..a850a10 100644 --- a/CryptoExchange.Net/CryptoExchange.Net.xml +++ b/CryptoExchange.Net/CryptoExchange.Net.xml @@ -3550,3 +3550,148 @@ +System.Diagnostics.CodeAnalysis.AllowNullAttribute"> + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + + + diff --git a/CryptoExchange.Net/SocketClient.cs b/CryptoExchange.Net/SocketClient.cs index b766eb8..dbce2d1 100644 --- a/CryptoExchange.Net/SocketClient.cs +++ b/CryptoExchange.Net/SocketClient.cs @@ -10,6 +10,7 @@ using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Logging; using CryptoExchange.Net.Objects; using CryptoExchange.Net.Sockets; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace CryptoExchange.Net @@ -78,6 +79,11 @@ namespace CryptoExchange.Net /// If false; data which is a response to a query won't get forwarded to subscriptions as well /// protected internal bool ContinueOnQueryResponse { get; protected set; } + + /// + /// If a message is received on the socket which is not handled by a handler this boolean determines whether this logs an error message + /// + protected internal bool UnhandledMessageExpected { get; set; } #endregion /// @@ -150,9 +156,14 @@ namespace CryptoExchange.Net released = true; } + var needsconnecting = !socket.Connected; + var connectResult = await ConnectIfNeeded(socket, authenticated).ConfigureAwait(false); if (!connectResult) return new CallResult(null, connectResult.Error); + + if (needsconnecting) + log.Write(LogVerbosity.Debug, $"Socket {socket.Socket.Id} connected to {url} {(request == null ? "with topic " + identifier: "with request " + JsonConvert.SerializeObject(request))}"); } finally { diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index 3f7b9e2..9dcc38b 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -178,7 +178,8 @@ namespace CryptoExchange.Net.Sockets if (!HandleData(tokenData) && !handledResponse) { - log.Write(LogVerbosity.Warning, "Message not handled: " + tokenData); + if (!socketClient.UnhandledMessageExpected) + log.Write(LogVerbosity.Warning, "Message not handled: " + tokenData); UnhandledMessage?.Invoke(tokenData); } } @@ -229,6 +230,8 @@ namespace CryptoExchange.Net.Sockets if (sw.ElapsedMilliseconds > 500) log.Write(LogVerbosity.Warning, $"Socket {Socket.Id} message processing slow ({sw.ElapsedMilliseconds}ms), consider offloading data handling to another thread. " + "Data from this socket may arrive late or not at all if message processing is continuously slow."); + else + log.Write(LogVerbosity.Debug, $"Socket {Socket.Id} message processed in {sw.ElapsedMilliseconds}ms"); return handled; } catch (Exception ex)