Skip to content

Commit cf42388

Browse files
committed
Add methods for semantic logging support
1 parent 570544a commit cf42388

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,58 @@ public static void Write(int logLevel, string message, string topic)
5151
Write(message, topic, logLevel);
5252
}
5353

54+
private static void LoggingFunc(string message, string topic, int logLevel, params string[] list)
55+
{
56+
IGXLogger log = GetLogger(topic);
57+
LogLevel logLvl = (LogLevel)logLevel;
58+
59+
switch (logLvl)
60+
{
61+
case LogLevel.Off:
62+
break;
63+
case LogLevel.Trace:
64+
GXLogging.Trace(log, message, list);
65+
break;
66+
case LogLevel.Debug:
67+
GXLogging.Debug(log, message, list);
68+
break;
69+
case LogLevel.Info:
70+
GXLogging.Info(log, message, list);
71+
break;
72+
case LogLevel.Warn:
73+
GXLogging.Warn(log, message, list);
74+
break;
75+
case LogLevel.Error:
76+
GXLogging.Error(log, message, list);
77+
break;
78+
case LogLevel.Fatal:
79+
GXLogging.Critical(log, message, list);
80+
break;
81+
default:
82+
GXLogging.Debug(log, message, list);
83+
break;
84+
}
85+
}
86+
public static void Write(string message, string topic, int logLevel, string propertyvalue1)
87+
{
88+
LoggingFunc(message, topic, logLevel, propertyvalue1);
89+
}
90+
public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2)
91+
{
92+
LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2);
93+
}
94+
public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2, string propertyvalue3)
95+
{
96+
LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2, propertyvalue3);
97+
}
98+
public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2, string propertyvalue3, string propertyvalue4)
99+
{
100+
LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2, propertyvalue3, propertyvalue4);
101+
}
102+
public static void Write(string message, string topic, int logLevel, string propertyvalue1, string propertyvalue2, string propertyvalue3, string propertyvalue4, string propertyvalue5)
103+
{
104+
LoggingFunc(message, topic, logLevel, propertyvalue1, propertyvalue2, propertyvalue3, propertyvalue4, propertyvalue5);
105+
}
54106
public static void Write(string message, string topic, int logLevel)
55107
{
56108
IGXLogger log = GetLogger(topic);

dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public interface IGXLogger
5959

6060

6161
void LogTrace(string value);
62+
void LogTrace(string value, params string[] list);
6263
void LogError(string msg, Exception ex);
6364

6465
void LogError(string msg);
@@ -119,6 +120,10 @@ public void LogTrace(string msg)
119120
{
120121
log.LogTrace(msg);
121122
}
123+
public void LogTrace(string msg, params string[] list)
124+
{
125+
log.LogTrace(msg, list);
126+
}
122127
public void LogError(string msg, Exception ex)
123128
{
124129
log.LogError(ex, msg);
@@ -252,6 +257,18 @@ public void LogTrace(string value)
252257
SetThreadIdForLogging();
253258
log.Logger.Log(MethodBase.GetCurrentMethod().DeclaringType, Level.Trace, value, null);
254259
}
260+
261+
public void LogTrace(string value, params string[] list)
262+
{
263+
SetThreadIdForLogging();
264+
StringBuilder message = new StringBuilder();
265+
message.Append(value);
266+
foreach (string parm in list)
267+
{
268+
message.Append(parm);
269+
}
270+
log.Logger.Log(MethodBase.GetCurrentMethod().DeclaringType, Level.Trace, message.ToString(), null);
271+
}
255272
public void LogError(string msg, Exception ex)
256273
{
257274
SetThreadIdForLogging();
@@ -506,6 +523,14 @@ internal static void Trace(IGXLogger logger, params string[] list)
506523
logger.LogTrace(string.Join(" ", list));
507524
}
508525
}
526+
internal static void Trace(IGXLogger logger, string msg, params string[] list)
527+
{
528+
if (logger != null)
529+
{
530+
if (logger.IsTraceEnabled)
531+
logger.LogTrace(msg, list);
532+
}
533+
}
509534
public static void Critical(IGXLogger logger, params string[] list)
510535
{
511536
if (logger != null)

dotnet/test/DotNetUnitTest/Log/LogTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public void TestLogOutput()
1414
GXLogging.Debug(log, "Test Debug");
1515
GXLogging.Info(log, "Test Info");
1616
GXLogging.Warn(log, "Test Warn");
17+
GXLogging.Trace(log, "Test Trace {p1}", "parameter1");
1718
}
1819
}
1920
}

0 commit comments

Comments
 (0)