From cf42388e73697861dae784e288fb7acb8b858592 Mon Sep 17 00:00:00 2001 From: sjuarezgx Date: Thu, 9 Nov 2023 10:13:35 -0300 Subject: [PATCH 1/2] Add methods for semantic logging support --- .../GxClasses/Diagnostics/Log.cs | 52 +++++++++++++++++++ .../GxClasses/Helpers/GXLogging.cs | 25 +++++++++ dotnet/test/DotNetUnitTest/Log/LogTest.cs | 1 + 3 files changed, 78 insertions(+) diff --git a/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs b/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs index d1947ed42..a658e7282 100644 --- a/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs +++ b/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs @@ -51,6 +51,58 @@ public static void Write(int logLevel, string message, string topic) Write(message, topic, logLevel); } + private static void LoggingFunc(string message, string topic, int logLevel, params string[] list) + { + IGXLogger log = GetLogger(topic); + LogLevel logLvl = (LogLevel)logLevel; + + switch (logLvl) + { + case LogLevel.Off: + break; + case LogLevel.Trace: + GXLogging.Trace(log, message, list); + break; + case LogLevel.Debug: + GXLogging.Debug(log, message, list); + break; + case LogLevel.Info: + GXLogging.Info(log, message, list); + break; + case LogLevel.Warn: + GXLogging.Warn(log, message, list); + break; + case LogLevel.Error: + GXLogging.Error(log, message, list); + break; + case LogLevel.Fatal: + GXLogging.Critical(log, message, list); + break; + default: + GXLogging.Debug(log, message, list); + break; + } + } + public static void Write(string message, string topic, int logLevel, string propertyvalue1) + { + LoggingFunc(message, topic, logLevel, propertyvalue1); + } + public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2) + { + LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2); + } + public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2, string propertyvalue3) + { + LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2, propertyvalue3); + } + public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2, string propertyvalue3, string propertyvalue4) + { + LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2, propertyvalue3, propertyvalue4); + } + public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2, string propertyvalue3, string propertyvalue4, string propertyvalue5) + { + LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2, propertyvalue3, propertyvalue4, propertyvalue5); + } public static void Write(string message, string topic, int logLevel) { IGXLogger log = GetLogger(topic); diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs index 0cfa76acf..e16bd773b 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs @@ -59,6 +59,7 @@ public interface IGXLogger void LogTrace(string value); + void LogTrace(string value, params string[] list); void LogError(string msg, Exception ex); void LogError(string msg); @@ -119,6 +120,10 @@ public void LogTrace(string msg) { log.LogTrace(msg); } + public void LogTrace(string msg, params string[] list) + { + log.LogTrace(msg, list); + } public void LogError(string msg, Exception ex) { log.LogError(ex, msg); @@ -252,6 +257,18 @@ public void LogTrace(string value) SetThreadIdForLogging(); log.Logger.Log(MethodBase.GetCurrentMethod().DeclaringType, Level.Trace, value, null); } + + public void LogTrace(string value, params string[] list) + { + SetThreadIdForLogging(); + StringBuilder message = new StringBuilder(); + message.Append(value); + foreach (string parm in list) + { + message.Append(parm); + } + log.Logger.Log(MethodBase.GetCurrentMethod().DeclaringType, Level.Trace, message.ToString(), null); + } public void LogError(string msg, Exception ex) { SetThreadIdForLogging(); @@ -506,6 +523,14 @@ internal static void Trace(IGXLogger logger, params string[] list) logger.LogTrace(string.Join(" ", list)); } } + internal static void Trace(IGXLogger logger, string msg, params string[] list) + { + if (logger != null) + { + if (logger.IsTraceEnabled) + logger.LogTrace(msg, list); + } + } public static void Critical(IGXLogger logger, params string[] list) { if (logger != null) diff --git a/dotnet/test/DotNetUnitTest/Log/LogTest.cs b/dotnet/test/DotNetUnitTest/Log/LogTest.cs index 980f8cade..c8bd0f681 100644 --- a/dotnet/test/DotNetUnitTest/Log/LogTest.cs +++ b/dotnet/test/DotNetUnitTest/Log/LogTest.cs @@ -14,6 +14,7 @@ public void TestLogOutput() GXLogging.Debug(log, "Test Debug"); GXLogging.Info(log, "Test Info"); GXLogging.Warn(log, "Test Warn"); + GXLogging.Trace(log, "Test Trace {p1}", "parameter1"); } } } From 1183f88a9253475d65e43002f3b2308b43e56937 Mon Sep 17 00:00:00 2001 From: sjuarezgx Date: Thu, 9 Nov 2023 10:25:33 -0300 Subject: [PATCH 2/2] revert to previous version of logtest for now. --- dotnet/test/DotNetUnitTest/Log/LogTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/test/DotNetUnitTest/Log/LogTest.cs b/dotnet/test/DotNetUnitTest/Log/LogTest.cs index c8bd0f681..980f8cade 100644 --- a/dotnet/test/DotNetUnitTest/Log/LogTest.cs +++ b/dotnet/test/DotNetUnitTest/Log/LogTest.cs @@ -14,7 +14,6 @@ public void TestLogOutput() GXLogging.Debug(log, "Test Debug"); GXLogging.Info(log, "Test Info"); GXLogging.Warn(log, "Test Warn"); - GXLogging.Trace(log, "Test Trace {p1}", "parameter1"); } } }