From 18954f4f53aff93bc36e92460657e62e979b4316 Mon Sep 17 00:00:00 2001 From: JKorf Date: Thu, 29 Jun 2023 20:07:26 +0200 Subject: [PATCH] Added optional log level parameter for trace logger --- CryptoExchange.Net/Objects/Options.cs | 329 ---------------------- CryptoExchange.Net/Objects/TraceLogger.cs | 13 +- 2 files changed, 12 insertions(+), 330 deletions(-) delete mode 100644 CryptoExchange.Net/Objects/Options.cs diff --git a/CryptoExchange.Net/Objects/Options.cs b/CryptoExchange.Net/Objects/Options.cs deleted file mode 100644 index dc2d6f0..0000000 --- a/CryptoExchange.Net/Objects/Options.cs +++ /dev/null @@ -1,329 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Net.Http; -//using CryptoExchange.Net.Authentication; -//using CryptoExchange.Net.Interfaces; -//using CryptoExchange.Net.Logging; -//using Microsoft.Extensions.Logging; - -//namespace CryptoExchange.Net.Objects -//{ -// /// -// /// Client options -// /// -// public abstract class ClientOptions -// { -// internal event Action? OnLoggingChanged; - -// private LogLevel _logLevel = LogLevel.Information; -// /// -// /// The minimum log level to output -// /// -// public LogLevel LogLevel -// { -// get => _logLevel; -// set -// { -// _logLevel = value; -// OnLoggingChanged?.Invoke(); -// } -// } - -// private List _logWriters = new List { new DebugLogger() }; -// /// -// /// The log writers -// /// -// public List LogWriters -// { -// get => _logWriters; -// set -// { -// _logWriters = value; -// OnLoggingChanged?.Invoke(); -// } -// } - -// /// -// /// Proxy to use when connecting -// /// -// public ApiProxy? Proxy { get; set; } - -// /// -// /// The api credentials used for signing requests to this API. -// /// -// public ApiCredentials? ApiCredentials { get; set; } - -// /// -// /// ctor -// /// -// public ClientOptions() -// { -// } - -// /// -// /// ctor -// /// -// /// Copy values for the provided options -// public ClientOptions(ClientOptions? clientOptions) -// { -// if (clientOptions == null) -// return; - -// LogLevel = clientOptions.LogLevel; -// LogWriters = clientOptions.LogWriters.ToList(); -// Proxy = clientOptions.Proxy; -// ApiCredentials = clientOptions.ApiCredentials?.Copy(); -// } - -// /// -// /// ctor -// /// -// /// Copy values for the provided options -// /// Copy values for the provided options -// internal ClientOptions(ClientOptions baseOptions, ClientOptions? newValues) -// { -// Proxy = newValues?.Proxy ?? baseOptions.Proxy; -// LogLevel = baseOptions.LogLevel; -// LogWriters = baseOptions.LogWriters.ToList(); -// ApiCredentials = newValues?.ApiCredentials?.Copy() ?? baseOptions.ApiCredentials?.Copy(); -// } - -// /// -// public override string ToString() -// { -// return $"LogLevel: {LogLevel}, Writers: {LogWriters.Count}, Proxy: {(Proxy == null ? "-" : Proxy.Host)}"; -// } -// } - -// /// -// /// API client options -// /// -// public class ApiClientOptions -// { -// /// -// /// If true, the CallResult and DataEvent objects will also include the originally received json data in the OriginalData property -// /// -// public bool OutputOriginalData { get; set; } = false; - -// /// -// /// The base address of the API -// /// -// public string BaseAddress { get; set; } - -// /// -// /// The api credentials used for signing requests to this API. Overrides API credentials provided in the client options -// /// -// public ApiCredentials? ApiCredentials { get; set; } - -// /// -// /// ctor -// /// -//#pragma warning disable 8618 // Will always get filled by the implementation -// public ApiClientOptions() -// { -// } -//#pragma warning restore 8618 - -// /// -// /// ctor -// /// -// /// Base address for the API -// public ApiClientOptions(string baseAddress) -// { -// BaseAddress = baseAddress; -// } - -// /// -// /// ctor -// /// -// /// Copy values for the provided options -// /// Copy values for the provided options -// public ApiClientOptions(ApiClientOptions baseOptions, ApiClientOptions? newValues) -// { -// BaseAddress = newValues?.BaseAddress ?? baseOptions.BaseAddress; -// ApiCredentials = newValues?.ApiCredentials?.Copy() ?? baseOptions.ApiCredentials?.Copy(); -// OutputOriginalData = newValues?.OutputOriginalData ?? baseOptions.OutputOriginalData; -// } - -// /// -// public override string ToString() -// { -// return $"OutputOriginalData: {OutputOriginalData}, Credentials: {(ApiCredentials == null ? "-" : "Set")}, BaseAddress: {BaseAddress}"; -// } -// } - -// /// -// /// Rest API client options -// /// -// public class RestApiClientOptions: ApiClientOptions -// { -// /// -// /// The time the server has to respond to a request before timing out -// /// -// public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30); - -// /// -// /// Http client to use. If a HttpClient is provided in this property the RequestTimeout and Proxy options provided in these options will be ignored in requests and should be set on the provided HttpClient instance -// /// -// public HttpClient? HttpClient { get; set; } - -// /// -// /// List of rate limiters to use -// /// -// public List RateLimiters { get; set; } = new List(); - -// /// -// /// What to do when a call would exceed the rate limit -// /// -// public RateLimitingBehaviour RateLimitingBehaviour { get; set; } = RateLimitingBehaviour.Wait; - -// /// -// /// Whether or not to automatically sync the local time with the server time -// /// -// public bool AutoTimestamp { get; set; } - -// /// -// /// How often the timestamp adjustment between client and server is recalculated. If you need a very small TimeSpan here you're probably better of syncing your server time more often -// /// -// public TimeSpan TimestampRecalculationInterval { get; set; } = TimeSpan.FromHours(1); - -// /// -// /// ctor -// /// -// public RestApiClientOptions() -// { -// } - -// /// -// /// ctor -// /// -// /// Base address for the API -// public RestApiClientOptions(string baseAddress): base(baseAddress) -// { -// } - -// /// -// /// ctor -// /// -// /// Copy values for the provided options -// /// Copy values for the provided options -// public RestApiClientOptions(RestApiClientOptions baseOn, RestApiClientOptions? newValues): base(baseOn, newValues) -// { -// HttpClient = newValues?.HttpClient ?? baseOn.HttpClient; -// RequestTimeout = newValues == default ? baseOn.RequestTimeout : newValues.RequestTimeout; -// RateLimitingBehaviour = newValues?.RateLimitingBehaviour ?? baseOn.RateLimitingBehaviour; -// AutoTimestamp = newValues?.AutoTimestamp ?? baseOn.AutoTimestamp; -// TimestampRecalculationInterval = newValues?.TimestampRecalculationInterval ?? baseOn.TimestampRecalculationInterval; -// RateLimiters = newValues?.RateLimiters.ToList() ?? baseOn?.RateLimiters.ToList() ?? new List(); -// } - -// /// -// public override string ToString() -// { -// return $"{base.ToString()}, RequestTimeout: {RequestTimeout:c}, HttpClient: {(HttpClient == null ? "-" : "set")}, RateLimiters: {RateLimiters?.Count}, RateLimitBehaviour: {RateLimitingBehaviour}, AutoTimestamp: {AutoTimestamp}, TimestampRecalculationInterval: {TimestampRecalculationInterval}"; -// } -// } - -// /// -// /// Rest API client options -// /// -// public class SocketApiClientOptions : ApiClientOptions -// { -// /// -// /// Whether or not the socket should automatically reconnect when losing connection -// /// -// public bool AutoReconnect { get; set; } = true; - -// /// -// /// Time to wait between reconnect attempts -// /// -// public TimeSpan ReconnectInterval { get; set; } = TimeSpan.FromSeconds(5); - -// /// -// /// Max number of concurrent resubscription tasks per socket after reconnecting a socket -// /// -// public int MaxConcurrentResubscriptionsPerSocket { get; set; } = 5; - -// /// -// /// The max time to wait for a response after sending a request on the socket before giving a timeout -// /// -// public TimeSpan SocketResponseTimeout { get; set; } = TimeSpan.FromSeconds(10); - -// /// -// /// The max time of not receiving any data after which the connection is assumed to be dropped. This can only be used for socket connections where a steady flow of data is expected, -// /// for example when the server sends intermittent ping requests -// /// -// public TimeSpan SocketNoDataTimeout { get; set; } - -// /// -// /// The amount of subscriptions that should be made on a single socket connection. Not all API's support multiple subscriptions on a single socket. -// /// Setting this to a higher number increases subscription speed because not every subscription needs to connect to the server, but having more subscriptions on a -// /// single connection will also increase the amount of traffic on that single connection, potentially leading to issues. -// /// -// public int? SocketSubscriptionsCombineTarget { get; set; } - -// /// -// /// The max amount of connections to make to the server. Can be used for API's which only allow a certain number of connections. Changing this to a high value might cause issues. -// /// -// public int? MaxSocketConnections { get; set; } - -// /// -// /// The time to wait after connecting a socket before sending messages. Can be used for API's which will rate limit if you subscribe directly after connecting. -// /// -// public TimeSpan DelayAfterConnect { get; set; } = TimeSpan.Zero; - -// /// -// /// ctor -// /// -// public SocketApiClientOptions() -// { -// } - -// /// -// /// ctor -// /// -// /// Base address for the API -// public SocketApiClientOptions(string baseAddress) : base(baseAddress) -// { -// } - -// /// -// /// ctor -// /// -// /// Copy values for the provided options -// /// Copy values for the provided options -// public SocketApiClientOptions(SocketApiClientOptions baseOptions, SocketApiClientOptions? newValues) : base(baseOptions, newValues) -// { -// if (baseOptions == null) -// return; - -// AutoReconnect = newValues?.AutoReconnect ?? baseOptions.AutoReconnect; -// ReconnectInterval = newValues?.ReconnectInterval ?? baseOptions.ReconnectInterval; -// MaxConcurrentResubscriptionsPerSocket = newValues?.MaxConcurrentResubscriptionsPerSocket ?? baseOptions.MaxConcurrentResubscriptionsPerSocket; -// SocketResponseTimeout = newValues?.SocketResponseTimeout ?? baseOptions.SocketResponseTimeout; -// SocketNoDataTimeout = newValues?.SocketNoDataTimeout ?? baseOptions.SocketNoDataTimeout; -// SocketSubscriptionsCombineTarget = newValues?.SocketSubscriptionsCombineTarget ?? baseOptions.SocketSubscriptionsCombineTarget; -// MaxSocketConnections = newValues?.MaxSocketConnections ?? baseOptions.MaxSocketConnections; -// DelayAfterConnect = newValues?.DelayAfterConnect ?? baseOptions.DelayAfterConnect; -// } - -// /// -// public override string ToString() -// { -// return $"{base.ToString()}, AutoReconnect: {AutoReconnect}, ReconnectInterval: {ReconnectInterval}, MaxConcurrentResubscriptionsPerSocket: {MaxConcurrentResubscriptionsPerSocket}, SocketResponseTimeout: {SocketResponseTimeout:c}, SocketNoDataTimeout: {SocketNoDataTimeout}, SocketSubscriptionsCombineTarget: {SocketSubscriptionsCombineTarget}, MaxSocketConnections: {MaxSocketConnections}"; -// } -// } - -// /// -// /// Base for order book options -// /// -// public class OrderBookOptions : ClientOptions -// { -// /// -// /// Whether or not checksum validation is enabled. Default is true, disabling will ignore checksum messages. -// /// -// public bool ChecksumValidationEnabled { get; set; } = true; -// } - -//} diff --git a/CryptoExchange.Net/Objects/TraceLogger.cs b/CryptoExchange.Net/Objects/TraceLogger.cs index 91128f5..3404cfb 100644 --- a/CryptoExchange.Net/Objects/TraceLogger.cs +++ b/CryptoExchange.Net/Objects/TraceLogger.cs @@ -9,8 +9,19 @@ namespace CryptoExchange.Net.Objects /// public class TraceLoggerProvider : ILoggerProvider { + private readonly LogLevel _logLevel; + + /// + /// ctor + /// + /// + public TraceLoggerProvider(LogLevel? logLevel = null) + { + _logLevel = logLevel ?? LogLevel.Trace; + } + /// - public ILogger CreateLogger(string categoryName) => new TraceLogger(categoryName); + public ILogger CreateLogger(string categoryName) => new TraceLogger(categoryName, _logLevel); /// public void Dispose() { } }