mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-10-09 12:41:43 +00:00
added optional request tracing id for much better logs reading
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
@@ -21,10 +22,15 @@ namespace CryptoExchange.Net.Requests
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="client"></param>
|
||||
public Request(HttpRequestMessage request, HttpClient client)
|
||||
/// <param name="isTracingEnabled">if true, should assign unique id for request</param>
|
||||
public Request(HttpRequestMessage request, HttpClient client, bool isTracingEnabled=false)
|
||||
{
|
||||
httpClient = client;
|
||||
this.request = request;
|
||||
if (isTracingEnabled)
|
||||
{
|
||||
RequestId = Path.GetRandomFileName();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -45,6 +51,8 @@ namespace CryptoExchange.Net.Requests
|
||||
|
||||
/// <inheritdoc />
|
||||
public Uri Uri => request.RequestUri;
|
||||
/// <inheritdoc />
|
||||
public string? RequestId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetContent(string data, string contentType)
|
||||
|
||||
@@ -12,10 +12,11 @@ namespace CryptoExchange.Net.Requests
|
||||
public class RequestFactory : IRequestFactory
|
||||
{
|
||||
private HttpClient? httpClient;
|
||||
|
||||
private bool isTracingEnabled;
|
||||
/// <inheritdoc />
|
||||
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy)
|
||||
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy, bool isTracingEnabled = false)
|
||||
{
|
||||
this.isTracingEnabled = isTracingEnabled;
|
||||
HttpMessageHandler handler = new HttpClientHandler()
|
||||
{
|
||||
Proxy = proxy == null ? null : new WebProxy
|
||||
@@ -25,7 +26,7 @@ namespace CryptoExchange.Net.Requests
|
||||
}
|
||||
};
|
||||
|
||||
httpClient = new HttpClient(handler) {Timeout = requestTimeout};
|
||||
httpClient = new HttpClient(handler) { Timeout = requestTimeout };
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -34,7 +35,7 @@ namespace CryptoExchange.Net.Requests
|
||||
if (httpClient == null)
|
||||
throw new InvalidOperationException("Cant create request before configuring http client");
|
||||
|
||||
return new Request(new HttpRequestMessage(method, uri), httpClient);
|
||||
return new Request(new HttpRequestMessage(method, uri), httpClient, isTracingEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user