Skip to content

Commit e072168

Browse files
Eliminate overhead in the Log API when logging is disabled.
1 parent 1a29537 commit e072168

File tree

1 file changed

+9
-5
lines changed
  • dotnet/src/dotnetframework/GxClasses/Diagnostics

1 file changed

+9
-5
lines changed

dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using GeneXus.Attributes;
22
using GeneXus.Configuration;
33
using log4net;
4+
using System.Collections.Concurrent;
5+
46
#if NETCORE
57
using GeneXus.Services.Log;
68
using Microsoft.Extensions.Logging;
@@ -26,17 +28,19 @@ private enum LogLevel
2628
private static readonly string DefaultRepository = LogManager.GetRepository().Name;
2729
private static readonly string DefaultUserLogNamespace = Config.GetValueOf("USER_LOG_NAMESPACE", LogConfiguration.USER_LOG_TOPIC);
2830
private static readonly IGXLogger GlobalLog = new GXLoggerLog4Net(LogManager.GetLogger(DefaultRepository, DefaultUserLogNamespace));
29-
31+
private static ConcurrentDictionary<string, IGXLogger> LoggerDictionary = new ConcurrentDictionary<string, IGXLogger>() { [string.Empty] = GlobalLog };
3032
internal static IGXLogger GetLogger(string topic)
3133
{
32-
if (!string.IsNullOrEmpty(topic))
34+
if (LoggerDictionary.TryGetValue(topic, out IGXLogger logger))
3335
{
34-
string loggerName = topic.StartsWith(LoggerPrefix) ? topic.Substring(1) : $"{DefaultUserLogNamespace}.{topic.Trim()}";
35-
return GXLoggerFactory.GetLogger(loggerName);
36+
return logger;
3637
}
3738
else
3839
{
39-
return GlobalLog;
40+
string loggerName = topic.StartsWith(LoggerPrefix) ? topic.Substring(1) : $"{DefaultUserLogNamespace}.{topic.Trim()}";
41+
logger = GXLoggerFactory.GetLogger(loggerName);
42+
LoggerDictionary.TryAdd(topic, logger);
43+
return logger;
4044
}
4145
}
4246

0 commit comments

Comments
 (0)