Skip to content

Commit 6f9b980

Browse files
committed
Extended logging
1 parent 29e3fd1 commit 6f9b980

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

GoAwayEdge/Common/Debugging/Logging.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Backported from: https://git.heydu.net/valnoxy/xorieos/-/blob/main/srv03rtm/base/ntsetup/winnt32/modernsetup/common/logging.cs
1515
*/
1616

17+
using System.Diagnostics;
1718
using System.IO;
1819
using System.Reflection;
1920

@@ -51,10 +52,23 @@ public static void Log(string message, LogLevel level = LogLevel.INFO)
5152
{
5253
if (string.IsNullOrEmpty(_logFile))
5354
throw new Exception("Logging class not initialized!");
54-
using var writer = new StreamWriter(_logFile, true);
5555

56-
var logMessage = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {level} - {message}";
57-
writer.WriteLine(logMessage);
56+
// Get calling method information
57+
var stackTrace = new StackTrace();
58+
var callingMethod = stackTrace.GetFrame(1)?.GetMethod();
59+
var callingClass = callingMethod?.DeclaringType?.FullName ?? "UnknownClass";
60+
var methodName = callingMethod?.Name ?? "UnknownMethod";
61+
62+
// Construct the log message with calling class and method
63+
var logMessage = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {level} - {callingClass}.{methodName} - {message}";
64+
65+
using (var fileStream = new FileStream(_logFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
66+
using (var writer = new StreamWriter(fileStream))
67+
{
68+
writer.WriteLine(logMessage);
69+
}
70+
71+
// Output log message to Debug console
5872
System.Diagnostics.Debug.WriteLine(logMessage);
5973
}
6074

@@ -72,4 +86,4 @@ private static void DeleteOldLogFiles()
7286
}
7387
}
7488
}
75-
}
89+
}

0 commit comments

Comments
 (0)