From 447435205d3ce876e565a685f97001b1db8c30a1 Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Thu, 2 Nov 2023 15:47:38 +0100 Subject: [PATCH] Improve telemetry tracking by avoiding null trace messages The changes in the AppInsightsRemoteLogger class's TrackTrace method ensure that no null or empty messages are sent to the telemetryClient. This prevents potential errors and useless logs. This modification is made after identifying cases of null or empty logs causing issues in the telemetry data. The updated function now checks if the message is null or whitespace before sending it to the telemetryClient. --- .../ApiClientCodeGen.Core/Logging/AppInsightsRemoteLogger.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Core/ApiClientCodeGen.Core/Logging/AppInsightsRemoteLogger.cs b/src/Core/ApiClientCodeGen.Core/Logging/AppInsightsRemoteLogger.cs index 6f3b857cef..3c6c6e90f8 100644 --- a/src/Core/ApiClientCodeGen.Core/Logging/AppInsightsRemoteLogger.cs +++ b/src/Core/ApiClientCodeGen.Core/Logging/AppInsightsRemoteLogger.cs @@ -84,7 +84,10 @@ public void WriteLine(object data) { if (TestingUtility.IsRunningFromUnitTest || Debugger.IsAttached || telemetryClient == null) return; - telemetryClient.TrackTrace(data.ToString()); + var message = data?.ToString(); + if (string.IsNullOrWhiteSpace(message)) + return; + telemetryClient.TrackTrace(message); telemetryClient.Flush(); } }