Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
26 changes: 20 additions & 6 deletions dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
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);
}
}
public static void Error(ILog log, string msg, Exception ex)
{
if (log.IsErrorEnabled)
{
EnsureThreadIdPropertyExistsInContext();
log.Error(msg, ex);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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)
{
Expand All @@ -76,13 +84,15 @@ public static void Warn(ILog log, string msg, Exception ex)
{
if (log.IsWarnEnabled)
{
EnsureThreadIdPropertyExistsInContext();
log.Warn(msg, ex);
}
}
public static void Debug(ILog log, Exception ex, params string[] list)
{
if (log.IsDebugEnabled)
{
EnsureThreadIdPropertyExistsInContext();
StringBuilder msg = new StringBuilder();
foreach (string parm in list)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -127,6 +138,7 @@ public static void Debug(ILog log, string startMsg, Func<string> buildMsg)
{
if (log.IsDebugEnabled)
{
EnsureThreadIdPropertyExistsInContext();
string msg = buildMsg();
log.Debug(startMsg + msg);
}
Expand All @@ -139,13 +151,15 @@ public static void Debug(ILog log, string msg, Exception ex)
{
if (log.IsDebugEnabled)
{
EnsureThreadIdPropertyExistsInContext();
log.Debug(msg, ex);
}
}
public static void Info(ILog log, params string[] list)
{
if (log.IsInfoEnabled)
{
EnsureThreadIdPropertyExistsInContext();
StringBuilder msg = new StringBuilder();
foreach (string parm in list)
{
Expand Down