diff --git a/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs b/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs index 17ede87d5..bc090573a 100644 --- a/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs +++ b/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs @@ -29,6 +29,7 @@ private enum LogLevel private static ILog GetLogger(string topic) { + GXLogging.EnsureThreadIdPropertyExistsInContext(); if (!String.IsNullOrEmpty(topic)) { string loggerName = topic.StartsWith("$") ? topic.Substring(1) : string.Format("{0}.{1}", defaultUserLogNamespace, topic.Trim()); diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs index c1bdede79..c93a60b9a 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs @@ -1,22 +1,26 @@ -using log4net; -using log4net.Core; using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Text; -using System.Text.RegularExpressions; +using System.Threading; +using log4net; +using log4net.Core; namespace GeneXus { public static class GXLogging { - + internal static void EnsureThreadIdPropertyExistsInContext() + { +#if NETCORE + log4net.ThreadContext.Properties["threadid"] ??= Thread.CurrentThread.ManagedThreadId; +#endif + } public static void Trace(this ILog log, params string[] list) { if (log.Logger.IsEnabledFor(Level.Trace)) { + EnsureThreadIdPropertyExistsInContext(); log.Logger.Log(MethodBase.GetCurrentMethod().DeclaringType, Level.Trace, String.Join(" ", list), null); } } @@ -24,6 +28,7 @@ public static void Error(ILog log, string msg, Exception ex) { if (log.IsErrorEnabled) { + EnsureThreadIdPropertyExistsInContext(); log.Error(msg, ex); } } @@ -32,6 +37,7 @@ public static void ErrorSanitized(ILog log, string msg, Exception ex) { if (log.IsErrorEnabled) { + EnsureThreadIdPropertyExistsInContext(); log.Error(Utils.StringUtil.Sanitize(msg, Utils.StringUtil.LogUserEntryWhiteList), ex); } } @@ -43,6 +49,7 @@ public static void Error(ILog log, string msg1, string msg2, Exception ex) public static void Error(ILog log, Exception ex, params string[] list) { if (log.IsErrorEnabled){ + EnsureThreadIdPropertyExistsInContext(); foreach (string parm in list){ log.Error(parm); } @@ -57,6 +64,7 @@ public static void Warn(ILog log, Exception ex, params string[] list) { if (log.IsWarnEnabled) { + EnsureThreadIdPropertyExistsInContext(); StringBuilder msg = new StringBuilder(); foreach (string parm in list) { @@ -76,6 +84,7 @@ public static void Warn(ILog log, string msg, Exception ex) { if (log.IsWarnEnabled) { + EnsureThreadIdPropertyExistsInContext(); log.Warn(msg, ex); } } @@ -83,6 +92,7 @@ public static void Debug(ILog log, Exception ex, params string[] list) { if (log.IsDebugEnabled) { + EnsureThreadIdPropertyExistsInContext(); StringBuilder msg = new StringBuilder(); foreach (string parm in list) { @@ -99,6 +109,7 @@ public static void DebugSanitized(ILog log, Exception ex, params string[] list) { if (log.IsDebugEnabled) { + EnsureThreadIdPropertyExistsInContext(); StringBuilder msg = new StringBuilder(); foreach (string parm in list) { @@ -127,6 +138,7 @@ public static void Debug(ILog log, string startMsg, Func buildMsg) { if (log.IsDebugEnabled) { + EnsureThreadIdPropertyExistsInContext(); string msg = buildMsg(); log.Debug(startMsg + msg); } @@ -139,6 +151,7 @@ public static void Debug(ILog log, string msg, Exception ex) { if (log.IsDebugEnabled) { + EnsureThreadIdPropertyExistsInContext(); log.Debug(msg, ex); } } @@ -146,6 +159,7 @@ public static void Info(ILog log, params string[] list) { if (log.IsInfoEnabled) { + EnsureThreadIdPropertyExistsInContext(); StringBuilder msg = new StringBuilder(); foreach (string parm in list) {