From f873a7042b969603f37e7444d642b78184d11a51 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Thu, 25 Apr 2019 11:28:06 +1200 Subject: [PATCH] feat: when tracing, pretty print the DNS response --- src/DnsClient.cs | 5 ++++- src/DohClient.cs | 4 +++- src/DotClient.cs | 2 ++ src/Udns.csproj | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/DnsClient.cs b/src/DnsClient.cs index f776b3d..b59172e 100644 --- a/src/DnsClient.cs +++ b/src/DnsClient.cs @@ -160,7 +160,10 @@ public override async Task QueryAsync( } } - log.Debug($"Got response #{response.Id}"); + if (log.IsDebugEnabled) + log.Debug($"Got response #{response.Id}"); + if (log.IsTraceEnabled) + log.Trace(response); return response; } diff --git a/src/DohClient.cs b/src/DohClient.cs index 65c98f4..b59aae0 100644 --- a/src/DohClient.cs +++ b/src/DohClient.cs @@ -62,7 +62,7 @@ public class DohClient : DnsClientBase public string ServerUrl { get; set; } = "https://cloudflare-dns.com/dns-query"; HttpClient httpClient; - object httpClientLock = new object(); + readonly object httpClientLock = new object(); readonly AsyncLock dnsServerLock = new AsyncLock(); /// @@ -159,6 +159,8 @@ public override async Task QueryAsync( if (log.IsDebugEnabled) log.Debug($"Got response #{dnsResponse.Id}"); + if (log.IsTraceEnabled) + log.Trace(dnsResponse); return dnsResponse; } diff --git a/src/DotClient.cs b/src/DotClient.cs index eb2d3b3..79aa953 100644 --- a/src/DotClient.cs +++ b/src/DotClient.cs @@ -394,6 +394,8 @@ void ReadResponses(Stream stream) // Find matching request. if (log.IsDebugEnabled) log.Debug($"Got response #{response.Id} {response.Status}"); + if (log.IsTraceEnabled) + log.Trace(response); if (!OutstandingRequests.TryGetValue(response.Id, out var task)) { log.Warn("DNS response is missing a matching request ID."); diff --git a/src/Udns.csproj b/src/Udns.csproj index 4c7bc84..27244f3 100644 --- a/src/Udns.csproj +++ b/src/Udns.csproj @@ -31,7 +31,7 @@ - +