From 57ad5c971fb85798ad2aa7b851da9d0afdc01f05 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:43:05 +0100 Subject: [PATCH 01/10] feat: CategoryTraceFilter --- Client.Core.Test/AbstractTest.cs | 23 ++++++++++++++++++++++- Client/Writes/Events.cs | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index d37163755..f0aa6788d 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Globalization; +using System.Linq; using System.Net.Http; using System.Text; using System.Threading; @@ -9,9 +10,29 @@ namespace InfluxDB.Client.Core.Test { + public class CategoryTraceFilter : TraceFilter + { + private readonly string[] categoryToFilter; + private readonly bool keep; + + public CategoryTraceFilter(string[] categoryToFilter, bool keep) + { + this.categoryToFilter = categoryToFilter; + this.keep = keep; + } + + public override bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data, object[] dataArray) + { + return categoryToFilter.Any(x => x == source) ^ keep; + } + } + public class AbstractTest { - private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out); + private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) + { + Filter = new CategoryTraceFilter(new string[] { "Influxdb-WRITE" }, false), + }; private static readonly int DefaultWait = 10; private static readonly int DefaultInfluxDBSleep = 100; diff --git a/Client/Writes/Events.cs b/Client/Writes/Events.cs index 3124a2b12..a7aa55fff 100644 --- a/Client/Writes/Events.cs +++ b/Client/Writes/Events.cs @@ -18,7 +18,7 @@ public WriteSuccessEvent(string organization, string bucket, WritePrecision prec internal override void LogEvent() { - Trace.WriteLine("The data was successfully written to InfluxDB 2."); + Trace.WriteLine("The data was successfully written to InfluxDB 2.", "Influxdb-WRITE"); } } From a0e70d9946d153facadf6004f7209510c36b2443 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:25:06 +0100 Subject: [PATCH 02/10] refactor:move CategoryTraceFilter to InfluxDB.core --- Client.Core.Test/AbstractTest.cs | 22 +++------------------- Client.Core/CategoryTraceFilter.cs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 Client.Core/CategoryTraceFilter.cs diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index f0aa6788d..b340b7a5f 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Globalization; -using System.Linq; using System.Net.Http; using System.Text; using System.Threading; @@ -10,28 +9,13 @@ namespace InfluxDB.Client.Core.Test { - public class CategoryTraceFilter : TraceFilter - { - private readonly string[] categoryToFilter; - private readonly bool keep; - - public CategoryTraceFilter(string[] categoryToFilter, bool keep) - { - this.categoryToFilter = categoryToFilter; - this.keep = keep; - } - - public override bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data, object[] dataArray) - { - return categoryToFilter.Any(x => x == source) ^ keep; - } - } - public class AbstractTest { private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { - Filter = new CategoryTraceFilter(new string[] { "Influxdb-WRITE" }, false), + Filter = new CategoryTraceFilter(new string[] { + CategoryTraceFilter.CategoryWrite + }, false), }; private static readonly int DefaultWait = 10; private static readonly int DefaultInfluxDBSleep = 100; diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/CategoryTraceFilter.cs new file mode 100644 index 000000000..fed3f80ba --- /dev/null +++ b/Client.Core/CategoryTraceFilter.cs @@ -0,0 +1,24 @@ +using System.Diagnostics; +using System.Linq; + +namespace InfluxDB.Client.Core +{ + public class CategoryTraceFilter : TraceFilter + { + public const string CategoryWrite = "influxdb-write"; + + private readonly string[] categoryToFilter; + private readonly bool keep; + + public CategoryTraceFilter(string[] categoryToFilter, bool keep) + { + this.categoryToFilter = categoryToFilter; + this.keep = keep; + } + + public override bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data, object[] dataArray) + { + return categoryToFilter.Any(x => x == source) ^ keep; + } + } +} \ No newline at end of file From 45374c5b2f0f4eba1bf70e41d846f7cab11797a1 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:49:25 +0100 Subject: [PATCH 03/10] feat: Trace marked as CategoryInflux --- Client.Core.Test/AbstractTest.cs | 2 +- Client.Core/CategoryTraceFilter.cs | 3 ++- Client.Core/Internal/AbstractQueryClient.cs | 4 ++-- Client.Core/Internal/AbstractRestClient.cs | 2 +- Client.Core/Internal/EnumConverter.cs | 2 +- Client.Core/Internal/LoggingHandler.cs | 16 ++++++++-------- Client/InfluxDBClient.cs | 4 ++-- Client/Internal/ApiClient.cs | 5 +++-- Client/Internal/MeasurementMapper.cs | 2 +- Client/Internal/RetryAttempt.cs | 4 +++- Client/UsersApi.cs | 2 +- Client/WriteApi.cs | 21 +++++++++++++-------- Client/WriteApiAsync.cs | 2 +- Client/Writes/Events.cs | 3 ++- 14 files changed, 41 insertions(+), 31 deletions(-) diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index b340b7a5f..6f9a08a15 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -14,7 +14,7 @@ public class AbstractTest private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { Filter = new CategoryTraceFilter(new string[] { - CategoryTraceFilter.CategoryWrite + CategoryTraceFilter.CategoryInflux }, false), }; private static readonly int DefaultWait = 10; diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/CategoryTraceFilter.cs index fed3f80ba..fe75eeb9d 100644 --- a/Client.Core/CategoryTraceFilter.cs +++ b/Client.Core/CategoryTraceFilter.cs @@ -1,11 +1,12 @@ using System.Diagnostics; using System.Linq; +using System; namespace InfluxDB.Client.Core { public class CategoryTraceFilter : TraceFilter { - public const string CategoryWrite = "influxdb-write"; + public const string CategoryInflux = "influx-client"; private readonly string[] categoryToFilter; private readonly bool keep; diff --git a/Client.Core/Internal/AbstractQueryClient.cs b/Client.Core/Internal/AbstractQueryClient.cs index c4d65b749..bf41ae07b 100644 --- a/Client.Core/Internal/AbstractQueryClient.cs +++ b/Client.Core/Internal/AbstractQueryClient.cs @@ -321,8 +321,8 @@ protected void CatchOrPropagateException(Exception exception, // if (IsCloseException(exception)) { - Trace.WriteLine("Socket closed by remote server or end of data"); - Trace.WriteLine(exception); + Trace.WriteLine("Socket closed by remote server or end of data", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine(exception, CategoryTraceFilter.CategoryInflux); } else { diff --git a/Client.Core/Internal/AbstractRestClient.cs b/Client.Core/Internal/AbstractRestClient.cs index 60692aae7..a833b7e97 100644 --- a/Client.Core/Internal/AbstractRestClient.cs +++ b/Client.Core/Internal/AbstractRestClient.cs @@ -25,7 +25,7 @@ protected async Task PingAsync(Task request) } catch (Exception e) { - Trace.WriteLine($"Error: {e.Message}"); + Trace.WriteLine($"Error: {e.Message}", CategoryTraceFilter.CategoryInflux); return false; } } diff --git a/Client.Core/Internal/EnumConverter.cs b/Client.Core/Internal/EnumConverter.cs index 39044aaa6..3d1dd2ba9 100644 --- a/Client.Core/Internal/EnumConverter.cs +++ b/Client.Core/Internal/EnumConverter.cs @@ -16,7 +16,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } catch (JsonSerializationException e) { - Trace.WriteLine($"Error converting enum value. Returning null. {e}"); + Trace.WriteLine($"Error converting enum value. Returning null. {e}", CategoryTraceFilter.CategoryInflux); return null; } diff --git a/Client.Core/Internal/LoggingHandler.cs b/Client.Core/Internal/LoggingHandler.cs index 478167934..7527a9ae6 100644 --- a/Client.Core/Internal/LoggingHandler.cs +++ b/Client.Core/Internal/LoggingHandler.cs @@ -27,7 +27,7 @@ public void BeforeIntercept(RestRequest request) var isBody = Level == LogLevel.Body; var isHeader = isBody || Level == LogLevel.Headers; - Trace.WriteLine($"--> {request.Method} {request.Resource}"); + Trace.WriteLine($"--> {request.Method} {request.Resource}", CategoryTraceFilter.CategoryInflux); if (isHeader) { @@ -56,12 +56,12 @@ public void BeforeIntercept(RestRequest request) stringBody = body.Value.ToString(); } - Trace.WriteLine($"--> Body: {stringBody}"); + Trace.WriteLine($"--> Body: {stringBody}", CategoryTraceFilter.CategoryInflux); } } - Trace.WriteLine("--> END"); - Trace.WriteLine("-->"); + Trace.WriteLine("--> END", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("-->", CategoryTraceFilter.CategoryInflux); } public object AfterIntercept(int statusCode, Func> headers, object body) @@ -75,7 +75,7 @@ public object AfterIntercept(int statusCode, Func> var isBody = Level == LogLevel.Body; var isHeader = isBody || Level == LogLevel.Headers; - Trace.WriteLine($"<-- {statusCode}"); + Trace.WriteLine($"<-- {statusCode}", CategoryTraceFilter.CategoryInflux); if (isHeader) { @@ -101,11 +101,11 @@ public object AfterIntercept(int statusCode, Func> if (!string.IsNullOrEmpty(stringBody)) { - Trace.WriteLine($"<-- Body: {stringBody}"); + Trace.WriteLine($"<-- Body: {stringBody}", CategoryTraceFilter.CategoryInflux); } } - Trace.WriteLine("<-- END"); + Trace.WriteLine("<-- END", CategoryTraceFilter.CategoryInflux); return freshBody; } @@ -131,7 +131,7 @@ private void LogHeaders(IEnumerable headers, string direction, var value = string.Equals(emp.Name, "Authorization", StringComparison.OrdinalIgnoreCase) ? "***" : emp.Value; - Trace.WriteLine($"{direction} {type}: {emp.Name}={value}"); + Trace.WriteLine($"{direction} {type}: {emp.Name}={value}", CategoryTraceFilter.CategoryInflux); } } } diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index d990b15bc..7df46da94 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -359,8 +359,8 @@ public void Dispose() } catch (Exception e) { - Trace.WriteLine("The signout exception"); - Trace.WriteLine(e); + Trace.WriteLine("The signout exception", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine(e, CategoryTraceFilter.CategoryInflux); } // diff --git a/Client/Internal/ApiClient.cs b/Client/Internal/ApiClient.cs index 5243d0107..b4842f619 100644 --- a/Client/Internal/ApiClient.cs +++ b/Client/Internal/ApiClient.cs @@ -7,6 +7,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; +using InfluxDB.Client.Core; using InfluxDB.Client.Core.Internal; using RestSharp; using RestSharp.Authenticators; @@ -133,8 +134,8 @@ private void InitToken() } catch (IOException e) { - Trace.WriteLine("Cannot retrieve the Session token!"); - Trace.WriteLine(e); + Trace.WriteLine("Cannot retrieve the Session token!", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine(e, CategoryTraceFilter.CategoryInflux); return; } diff --git a/Client/Internal/MeasurementMapper.cs b/Client/Internal/MeasurementMapper.cs index 236ccc33b..7b7c62473 100644 --- a/Client/Internal/MeasurementMapper.cs +++ b/Client/Internal/MeasurementMapper.cs @@ -97,7 +97,7 @@ internal PointData ToPoint(TM measurement, WritePrecision precision) } else { - Trace.WriteLine($"{value} is not supported as Timestamp"); + Trace.WriteLine($"{value} is not supported as Timestamp", CategoryTraceFilter.CategoryInflux); } } else diff --git a/Client/Internal/RetryAttempt.cs b/Client/Internal/RetryAttempt.cs index d274ee9da..cb8766965 100644 --- a/Client/Internal/RetryAttempt.cs +++ b/Client/Internal/RetryAttempt.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Net; using System.Net.Sockets; +using InfluxDB.Client.Core; using InfluxDB.Client.Core.Exceptions; namespace InfluxDB.Client.Internal @@ -141,7 +142,8 @@ internal long GetRetryInterval() var retryInterval = (long)(rangeStart + (rangeStop - rangeStart) * _random.NextDouble()); Trace.WriteLine("The InfluxDB does not specify \"Retry-After\". " + - $"Use the default retryInterval: {retryInterval}"); + $"Use the default retryInterval: {retryInterval}" + , CategoryTraceFilter.CategoryInflux); return retryInterval; } diff --git a/Client/UsersApi.cs b/Client/UsersApi.cs index bb4899a24..3053a7958 100644 --- a/Client/UsersApi.cs +++ b/Client/UsersApi.cs @@ -307,7 +307,7 @@ public async Task MeUpdatePasswordAsync(string oldPassword, string newPassword, var me = await MeAsync(cancellationToken).ConfigureAwait(false); if (me == null) { - Trace.WriteLine("User is not authenticated."); + Trace.WriteLine("User is not authenticated.", CategoryTraceFilter.CategoryInflux); return; } diff --git a/Client/WriteApi.cs b/Client/WriteApi.cs index 944e2cf81..2341022e9 100644 --- a/Client/WriteApi.cs +++ b/Client/WriteApi.cs @@ -300,14 +300,17 @@ protected internal WriteApi( switch (notification.Kind) { case NotificationKind.OnNext: - Trace.WriteLine($"The batch item: {notification} was processed successfully."); + Trace.WriteLine($"The batch item: {notification} was processed successfully." + , CategoryTraceFilter.CategoryInflux); break; case NotificationKind.OnError: Trace.WriteLine( - $"The batch item wasn't processed successfully because: {notification.Exception}"); + $"The batch item wasn't processed successfully because: {notification.Exception}" + , CategoryTraceFilter.CategoryInflux); break; default: - Trace.WriteLine($"The batch item: {notification} was processed"); + Trace.WriteLine($"The batch item: {notification} was processed" + , CategoryTraceFilter.CategoryInflux); break; } }, @@ -315,12 +318,14 @@ protected internal WriteApi( { Publish(new WriteRuntimeExceptionEvent(exception)); _disposed = true; - Trace.WriteLine($"The unhandled exception occurs: {exception}"); + Trace.WriteLine($"The unhandled exception occurs: {exception}" + , CategoryTraceFilter.CategoryInflux); }, () => { _disposed = true; - Trace.WriteLine("The WriteApi was disposed."); + Trace.WriteLine("The WriteApi was disposed." + , CategoryTraceFilter.CategoryInflux); }); } @@ -337,7 +342,7 @@ internal void ReleaseAndClose(int millis = 30000) { _unsubscribeDisposeCommand.Dispose(); // avoid duplicate call to dispose - Trace.WriteLine("Flushing batches before shutdown."); + Trace.WriteLine("Flushing batches before shutdown.", CategoryTraceFilter.CategoryInflux); if (!_subject.IsDisposed) { @@ -572,7 +577,7 @@ internal override string ToLineProtocol() { if (!_point.HasFields()) { - Trace.WriteLine($"The point: ${_point} doesn't contains any fields, skipping"); + Trace.WriteLine($"The point: ${_point} doesn't contains any fields, skipping", CategoryTraceFilter.CategoryInflux); return null; } @@ -603,7 +608,7 @@ internal override string ToLineProtocol() var point = _converter.ConvertToPointData(_measurement, Options.Precision); if (!point.HasFields()) { - Trace.WriteLine($"The point: ${point} doesn't contains any fields, skipping"); + Trace.WriteLine($"The point: ${point} doesn't contains any fields, skipping", CategoryTraceFilter.CategoryInflux); return null; } diff --git a/Client/WriteApiAsync.cs b/Client/WriteApiAsync.cs index b64249c0f..e4e71be79 100644 --- a/Client/WriteApiAsync.cs +++ b/Client/WriteApiAsync.cs @@ -411,7 +411,7 @@ private Task WriteData(string org, string bucket, WritePrecision precision, IEnu var sb = ToLineProtocolBody(data); if (sb.Length == 0) { - Trace.WriteLine($"The writes: {data} doesn't contains any Line Protocol, skipping"); + Trace.WriteLine($"The writes: {data} doesn't contains any Line Protocol, skipping", CategoryTraceFilter.CategoryInflux); return Task.CompletedTask; } diff --git a/Client/Writes/Events.cs b/Client/Writes/Events.cs index a7aa55fff..d24e4ef72 100644 --- a/Client/Writes/Events.cs +++ b/Client/Writes/Events.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using InfluxDB.Client.Api.Domain; +using InfluxDB.Client.Core; namespace InfluxDB.Client.Writes { @@ -18,7 +19,7 @@ public WriteSuccessEvent(string organization, string bucket, WritePrecision prec internal override void LogEvent() { - Trace.WriteLine("The data was successfully written to InfluxDB 2.", "Influxdb-WRITE"); + Trace.WriteLine("The data was successfully written to InfluxDB 2.", CategoryTraceFilter.CategoryInflux); } } From 3c45895a7f6632bb1bb78f8b5c38da7027e59acd Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:04:17 +0100 Subject: [PATCH 04/10] feat: SuppressInflux method --- Client.Core.Test/AbstractTest.cs | 4 +--- Client.Core/CategoryTraceFilter.cs | 8 +++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index 6f9a08a15..d3b47f5a3 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -13,9 +13,7 @@ public class AbstractTest { private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { - Filter = new CategoryTraceFilter(new string[] { - CategoryTraceFilter.CategoryInflux - }, false), + Filter = CategoryTraceFilter.SuppressInflux(), }; private static readonly int DefaultWait = 10; private static readonly int DefaultInfluxDBSleep = 100; diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/CategoryTraceFilter.cs index fe75eeb9d..44a7eb4fc 100644 --- a/Client.Core/CategoryTraceFilter.cs +++ b/Client.Core/CategoryTraceFilter.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Linq; -using System; namespace InfluxDB.Client.Core { @@ -21,5 +20,12 @@ public override bool ShouldTrace(TraceEventCache eventCache, string source, Trac { return categoryToFilter.Any(x => x == source) ^ keep; } + + public static CategoryTraceFilter SuppressInflux() + { + return new CategoryTraceFilter(new string[] { + CategoryInflux + }, false); + } } } \ No newline at end of file From 9074db8b3607e6b50894b205e9a3837b137980d2 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:06:30 +0100 Subject: [PATCH 05/10] docs: Filter trace verbose --- Client/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Client/README.md b/Client/README.md index 83e23b9b4..cd4a6d404 100644 --- a/Client/README.md +++ b/Client/README.md @@ -769,6 +769,31 @@ namespace Examples } ``` +## Filter trace verbose + +```cs +using System; +using System.Diagnostics; +using InfluxDB.Client.Core; + +namespace Examples +{ + public static class MyProgram + { + public static void Main() + { + TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) + { + Filter = CategoryTraceFilter.SuppressInflux(), + }; + Trace.Listeners.Add(ConsoleOutListener); + + // My code ... + } + } +} +```` + ## Management API The client has following management API: From dd7fb7983fcba88e0266c6aff1966a4059e990a8 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:51:53 +0100 Subject: [PATCH 06/10] docs: CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccd30181b..9c978d66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 4.14.0 [unreleased] +### Features + +1. [#590](https://github.com/influxdata/influxdb-client-csharp/pull/590): Allows disable Trace verbose messages + ### Dependencies Update dependencies: From 6e2ddf1ef42e06f8a64d6c22dcfbe92ca7dbb1d4 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Mon, 6 Nov 2023 08:41:43 +0100 Subject: [PATCH 07/10] style: indenting --- Client.Core.Test/AbstractTest.cs | 3 +- Client.Core/CategoryTraceFilter.cs | 62 ++++++++++++++------------- Client.Core/Internal/EnumConverter.cs | 3 +- Client/Internal/RetryAttempt.cs | 2 +- Client/WriteApi.cs | 14 +++--- Client/WriteApiAsync.cs | 3 +- 6 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index d3b47f5a3..eb7a665af 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -13,8 +13,9 @@ public class AbstractTest { private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { - Filter = CategoryTraceFilter.SuppressInflux(), + Filter = CategoryTraceFilter.SuppressInflux() }; + private static readonly int DefaultWait = 10; private static readonly int DefaultInfluxDBSleep = 100; diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/CategoryTraceFilter.cs index 44a7eb4fc..45d50ac4b 100644 --- a/Client.Core/CategoryTraceFilter.cs +++ b/Client.Core/CategoryTraceFilter.cs @@ -1,31 +1,33 @@ -using System.Diagnostics; -using System.Linq; - -namespace InfluxDB.Client.Core -{ - public class CategoryTraceFilter : TraceFilter - { - public const string CategoryInflux = "influx-client"; - - private readonly string[] categoryToFilter; - private readonly bool keep; - - public CategoryTraceFilter(string[] categoryToFilter, bool keep) - { - this.categoryToFilter = categoryToFilter; - this.keep = keep; - } - - public override bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data, object[] dataArray) - { - return categoryToFilter.Any(x => x == source) ^ keep; - } - - public static CategoryTraceFilter SuppressInflux() - { - return new CategoryTraceFilter(new string[] { - CategoryInflux - }, false); - } - } +using System.Diagnostics; +using System.Linq; + +namespace InfluxDB.Client.Core +{ + public class CategoryTraceFilter : TraceFilter + { + public const string CategoryInflux = "influx-client"; + + private readonly string[] categoryToFilter; + private readonly bool keep; + + public CategoryTraceFilter(string[] categoryToFilter, bool keep) + { + this.categoryToFilter = categoryToFilter; + this.keep = keep; + } + + public override bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, + string formatOrMessage, object[] args, object data, object[] dataArray) + { + return categoryToFilter.Any(x => x == source) ^ keep; + } + + public static CategoryTraceFilter SuppressInflux() + { + return new CategoryTraceFilter(new string[] + { + CategoryInflux + }, false); + } + } } \ No newline at end of file diff --git a/Client.Core/Internal/EnumConverter.cs b/Client.Core/Internal/EnumConverter.cs index 3d1dd2ba9..9a7bd01b7 100644 --- a/Client.Core/Internal/EnumConverter.cs +++ b/Client.Core/Internal/EnumConverter.cs @@ -16,7 +16,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } catch (JsonSerializationException e) { - Trace.WriteLine($"Error converting enum value. Returning null. {e}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"Error converting enum value. Returning null. {e}", + CategoryTraceFilter.CategoryInflux); return null; } diff --git a/Client/Internal/RetryAttempt.cs b/Client/Internal/RetryAttempt.cs index cb8766965..4de91d3f8 100644 --- a/Client/Internal/RetryAttempt.cs +++ b/Client/Internal/RetryAttempt.cs @@ -143,7 +143,7 @@ internal long GetRetryInterval() Trace.WriteLine("The InfluxDB does not specify \"Retry-After\". " + $"Use the default retryInterval: {retryInterval}" - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInflux); return retryInterval; } diff --git a/Client/WriteApi.cs b/Client/WriteApi.cs index 2341022e9..5615b4aa6 100644 --- a/Client/WriteApi.cs +++ b/Client/WriteApi.cs @@ -301,7 +301,7 @@ protected internal WriteApi( { case NotificationKind.OnNext: Trace.WriteLine($"The batch item: {notification} was processed successfully." - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInflux); break; case NotificationKind.OnError: Trace.WriteLine( @@ -310,7 +310,7 @@ protected internal WriteApi( break; default: Trace.WriteLine($"The batch item: {notification} was processed" - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInflux); break; } }, @@ -319,13 +319,13 @@ protected internal WriteApi( Publish(new WriteRuntimeExceptionEvent(exception)); _disposed = true; Trace.WriteLine($"The unhandled exception occurs: {exception}" - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInflux); }, () => { _disposed = true; Trace.WriteLine("The WriteApi was disposed." - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInflux); }); } @@ -577,7 +577,8 @@ internal override string ToLineProtocol() { if (!_point.HasFields()) { - Trace.WriteLine($"The point: ${_point} doesn't contains any fields, skipping", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"The point: ${_point} doesn't contains any fields, skipping", + CategoryTraceFilter.CategoryInflux); return null; } @@ -608,7 +609,8 @@ internal override string ToLineProtocol() var point = _converter.ConvertToPointData(_measurement, Options.Precision); if (!point.HasFields()) { - Trace.WriteLine($"The point: ${point} doesn't contains any fields, skipping", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"The point: ${point} doesn't contains any fields, skipping", + CategoryTraceFilter.CategoryInflux); return null; } diff --git a/Client/WriteApiAsync.cs b/Client/WriteApiAsync.cs index e4e71be79..80128660d 100644 --- a/Client/WriteApiAsync.cs +++ b/Client/WriteApiAsync.cs @@ -411,7 +411,8 @@ private Task WriteData(string org, string bucket, WritePrecision precision, IEnu var sb = ToLineProtocolBody(data); if (sb.Length == 0) { - Trace.WriteLine($"The writes: {data} doesn't contains any Line Protocol, skipping", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"The writes: {data} doesn't contains any Line Protocol, skipping", + CategoryTraceFilter.CategoryInflux); return Task.CompletedTask; } From 0a49f80bfd542f892cffaff41f327d0a209cb4c6 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:37:36 +0100 Subject: [PATCH 08/10] feat: trace categories error, query, write --- Client.Core.Test/AbstractTest.cs | 2 +- Client.Core/CategoryTraceFilter.cs | 25 ++++++++++++++++++++- Client.Core/Internal/AbstractQueryClient.cs | 5 +++-- Client.Core/Internal/AbstractRestClient.cs | 2 +- Client.Core/Internal/EnumConverter.cs | 2 +- Client.Core/Internal/LoggingHandler.cs | 16 ++++++------- Client/InfluxDBClient.cs | 4 ++-- Client/Internal/ApiClient.cs | 4 ++-- Client/Internal/MeasurementMapper.cs | 3 ++- Client/README.md | 2 +- Client/UsersApi.cs | 2 +- Client/WriteApi.cs | 16 ++++++------- Client/WriteApiAsync.cs | 2 +- Client/Writes/Events.cs | 3 ++- 14 files changed, 57 insertions(+), 31 deletions(-) diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index eb7a665af..763f596e3 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -13,7 +13,7 @@ public class AbstractTest { private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { - Filter = CategoryTraceFilter.SuppressInflux() + Filter = CategoryTraceFilter.SuppressInfluxVerbose() }; private static readonly int DefaultWait = 10; diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/CategoryTraceFilter.cs index 45d50ac4b..b74a394ee 100644 --- a/Client.Core/CategoryTraceFilter.cs +++ b/Client.Core/CategoryTraceFilter.cs @@ -6,6 +6,12 @@ namespace InfluxDB.Client.Core public class CategoryTraceFilter : TraceFilter { public const string CategoryInflux = "influx-client"; + public const string CategoryInfluxError = "influx-client-error"; + public const string CategoryInfluxQuery = "influx-client-query"; + public const string CategoryInfluxQueryError = "influx-client-query-error"; + public const string CategoryInfluxWrite = "influx-client-write"; + public const string CategoryInfluxWriteError = "influx-client-write-error"; + public const string CategoryInfluxLogger = "influx-client-logger"; private readonly string[] categoryToFilter; private readonly bool keep; @@ -26,7 +32,24 @@ public static CategoryTraceFilter SuppressInflux() { return new CategoryTraceFilter(new string[] { - CategoryInflux + CategoryInflux, + CategoryInfluxError, + CategoryInfluxQuery, + CategoryInfluxQueryError, + CategoryInfluxWrite, + CategoryInfluxWriteError, + CategoryInfluxLogger + }, false); + } + + public static CategoryTraceFilter SuppressInfluxVerbose() + { + return new CategoryTraceFilter(new string[] + { + CategoryInflux, + CategoryInfluxQuery, + CategoryInfluxWrite, + CategoryInfluxLogger }, false); } } diff --git a/Client.Core/Internal/AbstractQueryClient.cs b/Client.Core/Internal/AbstractQueryClient.cs index bf41ae07b..dade846f6 100644 --- a/Client.Core/Internal/AbstractQueryClient.cs +++ b/Client.Core/Internal/AbstractQueryClient.cs @@ -321,8 +321,9 @@ protected void CatchOrPropagateException(Exception exception, // if (IsCloseException(exception)) { - Trace.WriteLine("Socket closed by remote server or end of data", CategoryTraceFilter.CategoryInflux); - Trace.WriteLine(exception, CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("Socket closed by remote server or end of data", + CategoryTraceFilter.CategoryInfluxQueryError); + Trace.WriteLine(exception, CategoryTraceFilter.CategoryInfluxQueryError); } else { diff --git a/Client.Core/Internal/AbstractRestClient.cs b/Client.Core/Internal/AbstractRestClient.cs index a833b7e97..b80c6fd78 100644 --- a/Client.Core/Internal/AbstractRestClient.cs +++ b/Client.Core/Internal/AbstractRestClient.cs @@ -25,7 +25,7 @@ protected async Task PingAsync(Task request) } catch (Exception e) { - Trace.WriteLine($"Error: {e.Message}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"Error: {e.Message}", CategoryTraceFilter.CategoryInfluxError); return false; } } diff --git a/Client.Core/Internal/EnumConverter.cs b/Client.Core/Internal/EnumConverter.cs index 9a7bd01b7..223a0753b 100644 --- a/Client.Core/Internal/EnumConverter.cs +++ b/Client.Core/Internal/EnumConverter.cs @@ -17,7 +17,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist catch (JsonSerializationException e) { Trace.WriteLine($"Error converting enum value. Returning null. {e}", - CategoryTraceFilter.CategoryInflux); + CategoryTraceFilter.CategoryInfluxError); return null; } diff --git a/Client.Core/Internal/LoggingHandler.cs b/Client.Core/Internal/LoggingHandler.cs index 7527a9ae6..04a404869 100644 --- a/Client.Core/Internal/LoggingHandler.cs +++ b/Client.Core/Internal/LoggingHandler.cs @@ -27,7 +27,7 @@ public void BeforeIntercept(RestRequest request) var isBody = Level == LogLevel.Body; var isHeader = isBody || Level == LogLevel.Headers; - Trace.WriteLine($"--> {request.Method} {request.Resource}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"--> {request.Method} {request.Resource}", CategoryTraceFilter.CategoryInfluxLogger); if (isHeader) { @@ -56,12 +56,12 @@ public void BeforeIntercept(RestRequest request) stringBody = body.Value.ToString(); } - Trace.WriteLine($"--> Body: {stringBody}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"--> Body: {stringBody}", CategoryTraceFilter.CategoryInfluxLogger); } } - Trace.WriteLine("--> END", CategoryTraceFilter.CategoryInflux); - Trace.WriteLine("-->", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("--> END", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine("-->", CategoryTraceFilter.CategoryInfluxLogger); } public object AfterIntercept(int statusCode, Func> headers, object body) @@ -75,7 +75,7 @@ public object AfterIntercept(int statusCode, Func> var isBody = Level == LogLevel.Body; var isHeader = isBody || Level == LogLevel.Headers; - Trace.WriteLine($"<-- {statusCode}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"<-- {statusCode}", CategoryTraceFilter.CategoryInfluxLogger); if (isHeader) { @@ -101,11 +101,11 @@ public object AfterIntercept(int statusCode, Func> if (!string.IsNullOrEmpty(stringBody)) { - Trace.WriteLine($"<-- Body: {stringBody}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"<-- Body: {stringBody}", CategoryTraceFilter.CategoryInfluxLogger); } } - Trace.WriteLine("<-- END", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("<-- END", CategoryTraceFilter.CategoryInfluxLogger); return freshBody; } @@ -131,7 +131,7 @@ private void LogHeaders(IEnumerable headers, string direction, var value = string.Equals(emp.Name, "Authorization", StringComparison.OrdinalIgnoreCase) ? "***" : emp.Value; - Trace.WriteLine($"{direction} {type}: {emp.Name}={value}", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"{direction} {type}: {emp.Name}={value}", CategoryTraceFilter.CategoryInfluxLogger); } } } diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index 7df46da94..08884b1c6 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -359,8 +359,8 @@ public void Dispose() } catch (Exception e) { - Trace.WriteLine("The signout exception", CategoryTraceFilter.CategoryInflux); - Trace.WriteLine(e, CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("The signout exception", CategoryTraceFilter.CategoryInfluxError); + Trace.WriteLine(e, CategoryTraceFilter.CategoryInfluxError); } // diff --git a/Client/Internal/ApiClient.cs b/Client/Internal/ApiClient.cs index b4842f619..234cc2c57 100644 --- a/Client/Internal/ApiClient.cs +++ b/Client/Internal/ApiClient.cs @@ -134,8 +134,8 @@ private void InitToken() } catch (IOException e) { - Trace.WriteLine("Cannot retrieve the Session token!", CategoryTraceFilter.CategoryInflux); - Trace.WriteLine(e, CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("Cannot retrieve the Session token!", CategoryTraceFilter.CategoryInfluxError); + Trace.WriteLine(e, CategoryTraceFilter.CategoryInfluxError); return; } diff --git a/Client/Internal/MeasurementMapper.cs b/Client/Internal/MeasurementMapper.cs index 7b7c62473..6b1a589c3 100644 --- a/Client/Internal/MeasurementMapper.cs +++ b/Client/Internal/MeasurementMapper.cs @@ -97,7 +97,8 @@ internal PointData ToPoint(TM measurement, WritePrecision precision) } else { - Trace.WriteLine($"{value} is not supported as Timestamp", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine($"{value} is not supported as Timestamp", + CategoryTraceFilter.CategoryInfluxError); } } else diff --git a/Client/README.md b/Client/README.md index cd4a6d404..1e35a91ec 100644 --- a/Client/README.md +++ b/Client/README.md @@ -784,7 +784,7 @@ namespace Examples { TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { - Filter = CategoryTraceFilter.SuppressInflux(), + Filter = CategoryTraceFilter.SuppressInfluxVerbose(), }; Trace.Listeners.Add(ConsoleOutListener); diff --git a/Client/UsersApi.cs b/Client/UsersApi.cs index 3053a7958..54473b4a3 100644 --- a/Client/UsersApi.cs +++ b/Client/UsersApi.cs @@ -307,7 +307,7 @@ public async Task MeUpdatePasswordAsync(string oldPassword, string newPassword, var me = await MeAsync(cancellationToken).ConfigureAwait(false); if (me == null) { - Trace.WriteLine("User is not authenticated.", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("User is not authenticated.", CategoryTraceFilter.CategoryInfluxError); return; } diff --git a/Client/WriteApi.cs b/Client/WriteApi.cs index 5615b4aa6..9f9237bed 100644 --- a/Client/WriteApi.cs +++ b/Client/WriteApi.cs @@ -301,16 +301,16 @@ protected internal WriteApi( { case NotificationKind.OnNext: Trace.WriteLine($"The batch item: {notification} was processed successfully." - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInfluxWrite); break; case NotificationKind.OnError: Trace.WriteLine( $"The batch item wasn't processed successfully because: {notification.Exception}" - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInfluxWriteError); break; default: Trace.WriteLine($"The batch item: {notification} was processed" - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInfluxWrite); break; } }, @@ -319,13 +319,13 @@ protected internal WriteApi( Publish(new WriteRuntimeExceptionEvent(exception)); _disposed = true; Trace.WriteLine($"The unhandled exception occurs: {exception}" - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInfluxWriteError); }, () => { _disposed = true; Trace.WriteLine("The WriteApi was disposed." - , CategoryTraceFilter.CategoryInflux); + , CategoryTraceFilter.CategoryInfluxWrite); }); } @@ -342,7 +342,7 @@ internal void ReleaseAndClose(int millis = 30000) { _unsubscribeDisposeCommand.Dispose(); // avoid duplicate call to dispose - Trace.WriteLine("Flushing batches before shutdown.", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("Flushing batches before shutdown.", CategoryTraceFilter.CategoryInfluxWrite); if (!_subject.IsDisposed) { @@ -578,7 +578,7 @@ internal override string ToLineProtocol() if (!_point.HasFields()) { Trace.WriteLine($"The point: ${_point} doesn't contains any fields, skipping", - CategoryTraceFilter.CategoryInflux); + CategoryTraceFilter.CategoryInfluxWrite); return null; } @@ -610,7 +610,7 @@ internal override string ToLineProtocol() if (!point.HasFields()) { Trace.WriteLine($"The point: ${point} doesn't contains any fields, skipping", - CategoryTraceFilter.CategoryInflux); + CategoryTraceFilter.CategoryInfluxWrite); return null; } diff --git a/Client/WriteApiAsync.cs b/Client/WriteApiAsync.cs index 80128660d..7fc65b130 100644 --- a/Client/WriteApiAsync.cs +++ b/Client/WriteApiAsync.cs @@ -412,7 +412,7 @@ private Task WriteData(string org, string bucket, WritePrecision precision, IEnu if (sb.Length == 0) { Trace.WriteLine($"The writes: {data} doesn't contains any Line Protocol, skipping", - CategoryTraceFilter.CategoryInflux); + CategoryTraceFilter.CategoryInfluxWrite); return Task.CompletedTask; } diff --git a/Client/Writes/Events.cs b/Client/Writes/Events.cs index d24e4ef72..589e7c38f 100644 --- a/Client/Writes/Events.cs +++ b/Client/Writes/Events.cs @@ -19,7 +19,8 @@ public WriteSuccessEvent(string organization, string bucket, WritePrecision prec internal override void LogEvent() { - Trace.WriteLine("The data was successfully written to InfluxDB 2.", CategoryTraceFilter.CategoryInflux); + Trace.WriteLine("The data was successfully written to InfluxDB 2.", + CategoryTraceFilter.CategoryInfluxWrite); } } From 34c1ee6ee39e25e2741949c379cfda0e5f596282 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:04:59 +0100 Subject: [PATCH 09/10] refactor: rename InfluxDBTraceFilter, docs --- Client.Core.Test/AbstractTest.cs | 2 +- Client.Core/CategoryTraceFilter.cs | 30 +++++++++++++-------- Client.Core/Internal/AbstractQueryClient.cs | 4 +-- Client.Core/Internal/AbstractRestClient.cs | 2 +- Client.Core/Internal/EnumConverter.cs | 2 +- Client.Core/Internal/LoggingHandler.cs | 16 +++++------ Client/InfluxDBClient.cs | 4 +-- Client/Internal/ApiClient.cs | 4 +-- Client/Internal/MeasurementMapper.cs | 2 +- Client/Internal/RetryAttempt.cs | 2 +- Client/UsersApi.cs | 2 +- Client/WriteApi.cs | 16 +++++------ Client/WriteApiAsync.cs | 2 +- Client/Writes/Events.cs | 2 +- 14 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Client.Core.Test/AbstractTest.cs b/Client.Core.Test/AbstractTest.cs index 763f596e3..fffd93f3e 100644 --- a/Client.Core.Test/AbstractTest.cs +++ b/Client.Core.Test/AbstractTest.cs @@ -13,7 +13,7 @@ public class AbstractTest { private static readonly TraceListener ConsoleOutListener = new TextWriterTraceListener(Console.Out) { - Filter = CategoryTraceFilter.SuppressInfluxVerbose() + Filter = InfluxDBTraceFilter.SuppressInfluxVerbose() }; private static readonly int DefaultWait = 10; diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/CategoryTraceFilter.cs index b74a394ee..bf8d64f12 100644 --- a/Client.Core/CategoryTraceFilter.cs +++ b/Client.Core/CategoryTraceFilter.cs @@ -3,7 +3,7 @@ namespace InfluxDB.Client.Core { - public class CategoryTraceFilter : TraceFilter + public class InfluxDBTraceFilter : TraceFilter { public const string CategoryInflux = "influx-client"; public const string CategoryInfluxError = "influx-client-error"; @@ -13,24 +13,28 @@ public class CategoryTraceFilter : TraceFilter public const string CategoryInfluxWriteError = "influx-client-write-error"; public const string CategoryInfluxLogger = "influx-client-logger"; - private readonly string[] categoryToFilter; - private readonly bool keep; + private readonly string[] _categoryToFilter; + private readonly bool _keep; - public CategoryTraceFilter(string[] categoryToFilter, bool keep) + public InfluxDBTraceFilter(string[] categoryToFilter, bool keep) { - this.categoryToFilter = categoryToFilter; - this.keep = keep; + _categoryToFilter = categoryToFilter; + _keep = keep; } public override bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data, object[] dataArray) { - return categoryToFilter.Any(x => x == source) ^ keep; + return _categoryToFilter.Any(x => x == source) ^ _keep; } - public static CategoryTraceFilter SuppressInflux() + /// + /// Suppress all client trace messages. + /// + /// Trace Filter + public static InfluxDBTraceFilter SuppressInflux() { - return new CategoryTraceFilter(new string[] + return new InfluxDBTraceFilter(new string[] { CategoryInflux, CategoryInfluxError, @@ -42,9 +46,13 @@ public static CategoryTraceFilter SuppressInflux() }, false); } - public static CategoryTraceFilter SuppressInfluxVerbose() + /// + /// Suppress all client trace messages except , , . + /// + /// Trace Filter + public static InfluxDBTraceFilter SuppressInfluxVerbose() { - return new CategoryTraceFilter(new string[] + return new InfluxDBTraceFilter(new string[] { CategoryInflux, CategoryInfluxQuery, diff --git a/Client.Core/Internal/AbstractQueryClient.cs b/Client.Core/Internal/AbstractQueryClient.cs index dade846f6..519586783 100644 --- a/Client.Core/Internal/AbstractQueryClient.cs +++ b/Client.Core/Internal/AbstractQueryClient.cs @@ -322,8 +322,8 @@ protected void CatchOrPropagateException(Exception exception, if (IsCloseException(exception)) { Trace.WriteLine("Socket closed by remote server or end of data", - CategoryTraceFilter.CategoryInfluxQueryError); - Trace.WriteLine(exception, CategoryTraceFilter.CategoryInfluxQueryError); + InfluxDBTraceFilter.CategoryInfluxQueryError); + Trace.WriteLine(exception, InfluxDBTraceFilter.CategoryInfluxQueryError); } else { diff --git a/Client.Core/Internal/AbstractRestClient.cs b/Client.Core/Internal/AbstractRestClient.cs index b80c6fd78..eee5220e9 100644 --- a/Client.Core/Internal/AbstractRestClient.cs +++ b/Client.Core/Internal/AbstractRestClient.cs @@ -25,7 +25,7 @@ protected async Task PingAsync(Task request) } catch (Exception e) { - Trace.WriteLine($"Error: {e.Message}", CategoryTraceFilter.CategoryInfluxError); + Trace.WriteLine($"Error: {e.Message}", InfluxDBTraceFilter.CategoryInfluxError); return false; } } diff --git a/Client.Core/Internal/EnumConverter.cs b/Client.Core/Internal/EnumConverter.cs index 223a0753b..72cf8016b 100644 --- a/Client.Core/Internal/EnumConverter.cs +++ b/Client.Core/Internal/EnumConverter.cs @@ -17,7 +17,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist catch (JsonSerializationException e) { Trace.WriteLine($"Error converting enum value. Returning null. {e}", - CategoryTraceFilter.CategoryInfluxError); + InfluxDBTraceFilter.CategoryInfluxError); return null; } diff --git a/Client.Core/Internal/LoggingHandler.cs b/Client.Core/Internal/LoggingHandler.cs index 04a404869..c5ae2c6e7 100644 --- a/Client.Core/Internal/LoggingHandler.cs +++ b/Client.Core/Internal/LoggingHandler.cs @@ -27,7 +27,7 @@ public void BeforeIntercept(RestRequest request) var isBody = Level == LogLevel.Body; var isHeader = isBody || Level == LogLevel.Headers; - Trace.WriteLine($"--> {request.Method} {request.Resource}", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine($"--> {request.Method} {request.Resource}", InfluxDBTraceFilter.CategoryInfluxLogger); if (isHeader) { @@ -56,12 +56,12 @@ public void BeforeIntercept(RestRequest request) stringBody = body.Value.ToString(); } - Trace.WriteLine($"--> Body: {stringBody}", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine($"--> Body: {stringBody}", InfluxDBTraceFilter.CategoryInfluxLogger); } } - Trace.WriteLine("--> END", CategoryTraceFilter.CategoryInfluxLogger); - Trace.WriteLine("-->", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine("--> END", InfluxDBTraceFilter.CategoryInfluxLogger); + Trace.WriteLine("-->", InfluxDBTraceFilter.CategoryInfluxLogger); } public object AfterIntercept(int statusCode, Func> headers, object body) @@ -75,7 +75,7 @@ public object AfterIntercept(int statusCode, Func> var isBody = Level == LogLevel.Body; var isHeader = isBody || Level == LogLevel.Headers; - Trace.WriteLine($"<-- {statusCode}", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine($"<-- {statusCode}", InfluxDBTraceFilter.CategoryInfluxLogger); if (isHeader) { @@ -101,11 +101,11 @@ public object AfterIntercept(int statusCode, Func> if (!string.IsNullOrEmpty(stringBody)) { - Trace.WriteLine($"<-- Body: {stringBody}", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine($"<-- Body: {stringBody}", InfluxDBTraceFilter.CategoryInfluxLogger); } } - Trace.WriteLine("<-- END", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine("<-- END", InfluxDBTraceFilter.CategoryInfluxLogger); return freshBody; } @@ -131,7 +131,7 @@ private void LogHeaders(IEnumerable headers, string direction, var value = string.Equals(emp.Name, "Authorization", StringComparison.OrdinalIgnoreCase) ? "***" : emp.Value; - Trace.WriteLine($"{direction} {type}: {emp.Name}={value}", CategoryTraceFilter.CategoryInfluxLogger); + Trace.WriteLine($"{direction} {type}: {emp.Name}={value}", InfluxDBTraceFilter.CategoryInfluxLogger); } } } diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index 08884b1c6..6ab932297 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -359,8 +359,8 @@ public void Dispose() } catch (Exception e) { - Trace.WriteLine("The signout exception", CategoryTraceFilter.CategoryInfluxError); - Trace.WriteLine(e, CategoryTraceFilter.CategoryInfluxError); + Trace.WriteLine("The signout exception", InfluxDBTraceFilter.CategoryInfluxError); + Trace.WriteLine(e, InfluxDBTraceFilter.CategoryInfluxError); } // diff --git a/Client/Internal/ApiClient.cs b/Client/Internal/ApiClient.cs index 234cc2c57..a072a2e33 100644 --- a/Client/Internal/ApiClient.cs +++ b/Client/Internal/ApiClient.cs @@ -134,8 +134,8 @@ private void InitToken() } catch (IOException e) { - Trace.WriteLine("Cannot retrieve the Session token!", CategoryTraceFilter.CategoryInfluxError); - Trace.WriteLine(e, CategoryTraceFilter.CategoryInfluxError); + Trace.WriteLine("Cannot retrieve the Session token!", InfluxDBTraceFilter.CategoryInfluxError); + Trace.WriteLine(e, InfluxDBTraceFilter.CategoryInfluxError); return; } diff --git a/Client/Internal/MeasurementMapper.cs b/Client/Internal/MeasurementMapper.cs index 6b1a589c3..4dbca6164 100644 --- a/Client/Internal/MeasurementMapper.cs +++ b/Client/Internal/MeasurementMapper.cs @@ -98,7 +98,7 @@ internal PointData ToPoint(TM measurement, WritePrecision precision) else { Trace.WriteLine($"{value} is not supported as Timestamp", - CategoryTraceFilter.CategoryInfluxError); + InfluxDBTraceFilter.CategoryInfluxError); } } else diff --git a/Client/Internal/RetryAttempt.cs b/Client/Internal/RetryAttempt.cs index 4de91d3f8..0d7eb2415 100644 --- a/Client/Internal/RetryAttempt.cs +++ b/Client/Internal/RetryAttempt.cs @@ -143,7 +143,7 @@ internal long GetRetryInterval() Trace.WriteLine("The InfluxDB does not specify \"Retry-After\". " + $"Use the default retryInterval: {retryInterval}" - , CategoryTraceFilter.CategoryInflux); + , InfluxDBTraceFilter.CategoryInflux); return retryInterval; } diff --git a/Client/UsersApi.cs b/Client/UsersApi.cs index 54473b4a3..2b9aa2226 100644 --- a/Client/UsersApi.cs +++ b/Client/UsersApi.cs @@ -307,7 +307,7 @@ public async Task MeUpdatePasswordAsync(string oldPassword, string newPassword, var me = await MeAsync(cancellationToken).ConfigureAwait(false); if (me == null) { - Trace.WriteLine("User is not authenticated.", CategoryTraceFilter.CategoryInfluxError); + Trace.WriteLine("User is not authenticated.", InfluxDBTraceFilter.CategoryInfluxError); return; } diff --git a/Client/WriteApi.cs b/Client/WriteApi.cs index 9f9237bed..bff60a8e1 100644 --- a/Client/WriteApi.cs +++ b/Client/WriteApi.cs @@ -301,16 +301,16 @@ protected internal WriteApi( { case NotificationKind.OnNext: Trace.WriteLine($"The batch item: {notification} was processed successfully." - , CategoryTraceFilter.CategoryInfluxWrite); + , InfluxDBTraceFilter.CategoryInfluxWrite); break; case NotificationKind.OnError: Trace.WriteLine( $"The batch item wasn't processed successfully because: {notification.Exception}" - , CategoryTraceFilter.CategoryInfluxWriteError); + , InfluxDBTraceFilter.CategoryInfluxWriteError); break; default: Trace.WriteLine($"The batch item: {notification} was processed" - , CategoryTraceFilter.CategoryInfluxWrite); + , InfluxDBTraceFilter.CategoryInfluxWrite); break; } }, @@ -319,13 +319,13 @@ protected internal WriteApi( Publish(new WriteRuntimeExceptionEvent(exception)); _disposed = true; Trace.WriteLine($"The unhandled exception occurs: {exception}" - , CategoryTraceFilter.CategoryInfluxWriteError); + , InfluxDBTraceFilter.CategoryInfluxWriteError); }, () => { _disposed = true; Trace.WriteLine("The WriteApi was disposed." - , CategoryTraceFilter.CategoryInfluxWrite); + , InfluxDBTraceFilter.CategoryInfluxWrite); }); } @@ -342,7 +342,7 @@ internal void ReleaseAndClose(int millis = 30000) { _unsubscribeDisposeCommand.Dispose(); // avoid duplicate call to dispose - Trace.WriteLine("Flushing batches before shutdown.", CategoryTraceFilter.CategoryInfluxWrite); + Trace.WriteLine("Flushing batches before shutdown.", InfluxDBTraceFilter.CategoryInfluxWrite); if (!_subject.IsDisposed) { @@ -578,7 +578,7 @@ internal override string ToLineProtocol() if (!_point.HasFields()) { Trace.WriteLine($"The point: ${_point} doesn't contains any fields, skipping", - CategoryTraceFilter.CategoryInfluxWrite); + InfluxDBTraceFilter.CategoryInfluxWrite); return null; } @@ -610,7 +610,7 @@ internal override string ToLineProtocol() if (!point.HasFields()) { Trace.WriteLine($"The point: ${point} doesn't contains any fields, skipping", - CategoryTraceFilter.CategoryInfluxWrite); + InfluxDBTraceFilter.CategoryInfluxWrite); return null; } diff --git a/Client/WriteApiAsync.cs b/Client/WriteApiAsync.cs index 7fc65b130..bd926637b 100644 --- a/Client/WriteApiAsync.cs +++ b/Client/WriteApiAsync.cs @@ -412,7 +412,7 @@ private Task WriteData(string org, string bucket, WritePrecision precision, IEnu if (sb.Length == 0) { Trace.WriteLine($"The writes: {data} doesn't contains any Line Protocol, skipping", - CategoryTraceFilter.CategoryInfluxWrite); + InfluxDBTraceFilter.CategoryInfluxWrite); return Task.CompletedTask; } diff --git a/Client/Writes/Events.cs b/Client/Writes/Events.cs index 589e7c38f..14ae98db8 100644 --- a/Client/Writes/Events.cs +++ b/Client/Writes/Events.cs @@ -20,7 +20,7 @@ public WriteSuccessEvent(string organization, string bucket, WritePrecision prec internal override void LogEvent() { Trace.WriteLine("The data was successfully written to InfluxDB 2.", - CategoryTraceFilter.CategoryInfluxWrite); + InfluxDBTraceFilter.CategoryInfluxWrite); } } From 6343308597501d6f8cfe76868100edf1793d8636 Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:05:09 +0100 Subject: [PATCH 10/10] refactor: rename InfluxDBTraceFilter --- Client.Core/{CategoryTraceFilter.cs => InfluxDBTraceFilter.cs} | 3 +++ Client/README.md | 2 ++ 2 files changed, 5 insertions(+) rename Client.Core/{CategoryTraceFilter.cs => InfluxDBTraceFilter.cs} (94%) diff --git a/Client.Core/CategoryTraceFilter.cs b/Client.Core/InfluxDBTraceFilter.cs similarity index 94% rename from Client.Core/CategoryTraceFilter.cs rename to Client.Core/InfluxDBTraceFilter.cs index bf8d64f12..3eb5814c5 100644 --- a/Client.Core/CategoryTraceFilter.cs +++ b/Client.Core/InfluxDBTraceFilter.cs @@ -3,6 +3,9 @@ namespace InfluxDB.Client.Core { + /// + /// The is used to filter client trace messages by category. + /// public class InfluxDBTraceFilter : TraceFilter { public const string CategoryInflux = "influx-client"; diff --git a/Client/README.md b/Client/README.md index 1e35a91ec..4665d60c6 100644 --- a/Client/README.md +++ b/Client/README.md @@ -771,6 +771,8 @@ namespace Examples ## Filter trace verbose +You can filter out verbose messages from `InfluxDB.Client` by using TraceListener. + ```cs using System; using System.Diagnostics; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy