From 6acfda17e5aadfd3ec6d4ba3c7002d6dc6870b61 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Wed, 11 Dec 2024 16:28:45 +0800 Subject: [PATCH 01/11] init --- src/common/ManagedCommon/LanguageHelper.cs | 2 +- src/common/ManagedCommon/ManagedCommon.csproj | 1 + .../ManagedCommonJsonSerializerContext.cs | 13 +++++++++++++ src/common/ManagedCommon/NativeMethods.cs | 2 +- src/common/ManagedCommon/ThemeListener.cs | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs diff --git a/src/common/ManagedCommon/LanguageHelper.cs b/src/common/ManagedCommon/LanguageHelper.cs index 85cdcd1c335e..042e57bd8597 100644 --- a/src/common/ManagedCommon/LanguageHelper.cs +++ b/src/common/ManagedCommon/LanguageHelper.cs @@ -35,7 +35,7 @@ public static string LoadLanguage() inputStream.Close(); reader.Dispose(); - return JsonSerializer.Deserialize(data).LanguageTag; + return JsonSerializer.Deserialize(data, ManagedCommonJsonSerializerContext.Default.OutGoingLanguageSettings).LanguageTag; } catch (Exception) { diff --git a/src/common/ManagedCommon/ManagedCommon.csproj b/src/common/ManagedCommon/ManagedCommon.csproj index f3b149616c4c..bd7425307356 100644 --- a/src/common/ManagedCommon/ManagedCommon.csproj +++ b/src/common/ManagedCommon/ManagedCommon.csproj @@ -1,6 +1,7 @@  + PowerToys ManagedCommon diff --git a/src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs b/src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs new file mode 100644 index 000000000000..56c5d2c362de --- /dev/null +++ b/src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; +using static ManagedCommon.LanguageHelper; + +namespace ManagedCommon; + +[JsonSerializable(typeof(OutGoingLanguageSettings))] +internal sealed partial class ManagedCommonJsonSerializerContext : JsonSerializerContext +{ +} diff --git a/src/common/ManagedCommon/NativeMethods.cs b/src/common/ManagedCommon/NativeMethods.cs index feffafa94637..96a94a3527ec 100644 --- a/src/common/ManagedCommon/NativeMethods.cs +++ b/src/common/ManagedCommon/NativeMethods.cs @@ -50,7 +50,7 @@ public struct INPUT internal static int Size { - get { return Marshal.SizeOf(typeof(INPUT)); } + get { return Marshal.SizeOf(); } } } diff --git a/src/common/ManagedCommon/ThemeListener.cs b/src/common/ManagedCommon/ThemeListener.cs index 4e7475458155..945ab37debab 100644 --- a/src/common/ManagedCommon/ThemeListener.cs +++ b/src/common/ManagedCommon/ThemeListener.cs @@ -14,7 +14,7 @@ namespace ManagedCommon /// Sender ThemeListener public delegate void ThemeChangedEvent(ThemeListener sender); - public class ThemeListener : IDisposable + public partial class ThemeListener : IDisposable { /// /// Gets the App Theme. From f648b7a1fecf30f84fbe6a4947c95bb24b601045 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Fri, 13 Dec 2024 08:39:56 +0800 Subject: [PATCH 02/11] update --- src/common/ManagedCommon/Logger.cs | 78 +++++++----------------- src/common/ManagedCommon/RunnerHelper.cs | 7 +-- 2 files changed, 24 insertions(+), 61 deletions(-) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index 78b27afefcfc..04a3f8d3df1c 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -16,7 +16,7 @@ namespace ManagedCommon public static class Logger { private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); - private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion; + private static readonly string Version = FileVersionInfo.GetVersionInfo(Path.Combine(System.AppContext.BaseDirectory, ApplicationName)).ProductVersion; private static readonly string Error = "Error"; private static readonly string Warning = "Warning"; @@ -24,6 +24,8 @@ public static class Logger private static readonly string Debug = "Debug"; private static readonly string TraceFlag = "Trace"; + private static readonly string ApplicationName = "PowerToys.exe"; + /// /// Initializes the logger and sets the path for logging. /// @@ -54,17 +56,17 @@ public static void InitializeLogger(string applicationLogPath, bool isLocalLow = } [MethodImpl(MethodImplOptions.NoInlining)] - public static void LogError(string message) + public static void LogError(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { - Log(message, Error); + Log(message, Error, memberName, sourceFilePath, sourceLineNumber); } [MethodImpl(MethodImplOptions.NoInlining)] - public static void LogError(string message, Exception ex) + public static void LogError(string message, Exception ex, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { if (ex == null) { - Log(message, Error); + Log(message, Error, memberName, sourceFilePath, sourceLineNumber); } else { @@ -83,38 +85,38 @@ public static void LogError(string message, Exception ex) "Stack trace: " + Environment.NewLine + ex.StackTrace; - Log(exMessage, Error); + Log(exMessage, Error, memberName, sourceFilePath, sourceLineNumber); } } [MethodImpl(MethodImplOptions.NoInlining)] - public static void LogWarning(string message) + public static void LogWarning(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { - Log(message, Warning); + Log(message, Warning, memberName, sourceFilePath, sourceLineNumber); } [MethodImpl(MethodImplOptions.NoInlining)] - public static void LogInfo(string message) + public static void LogInfo(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { - Log(message, Info); + Log(message, Info, memberName, sourceFilePath, sourceLineNumber); } [MethodImpl(MethodImplOptions.NoInlining)] - public static void LogDebug(string message) + public static void LogDebug(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { - Log(message, Debug); + Log(message, Debug, memberName, sourceFilePath, sourceLineNumber); } [MethodImpl(MethodImplOptions.NoInlining)] - public static void LogTrace() + public static void LogTrace([System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { - Log(string.Empty, TraceFlag); + Log(string.Empty, TraceFlag, memberName, sourceFilePath, sourceLineNumber); } [MethodImpl(MethodImplOptions.NoInlining)] - private static void Log(string message, string type) + private static void Log(string message, string type, string memberName, string sourceFilePath, int sourceLineNumber) { - Trace.WriteLine("[" + DateTime.Now.TimeOfDay + "] [" + type + "] " + GetCallerInfo()); + Trace.WriteLine("[" + DateTime.Now.TimeOfDay + "] [" + type + "] " + GetCallerInfo(memberName, sourceFilePath, sourceLineNumber)); Trace.Indent(); if (message != string.Empty) { @@ -124,49 +126,11 @@ private static void Log(string message, string type) Trace.Unindent(); } - [MethodImpl(MethodImplOptions.NoInlining)] - private static string GetCallerInfo() - { - StackTrace stackTrace = new(); - - var callerMethod = GetCallerMethod(stackTrace); - - return $"{callerMethod?.DeclaringType?.Name}::{callerMethod.Name}"; - } - - private static MethodBase GetCallerMethod(StackTrace stackTrace) + private static string GetCallerInfo(string memberName, string sourceFilePath, int sourceLineNumber) { - const int topFrame = 3; - - var topMethod = stackTrace.GetFrame(topFrame)?.GetMethod(); - - try - { - if (topMethod?.Name == nameof(IAsyncStateMachine.MoveNext) && typeof(IAsyncStateMachine).IsAssignableFrom(topMethod?.DeclaringType)) - { - // Async method; return actual method as determined by heuristic: - // "Nearest method on stack to async state-machine's MoveNext() in same namespace but in a different type". - // There are tighter ways of determining the actual method, but this is good enough and probably faster. - for (int deepFrame = topFrame + 1; deepFrame < stackTrace.FrameCount; deepFrame++) - { - var deepMethod = stackTrace.GetFrame(deepFrame)?.GetMethod(); - - if (deepMethod?.DeclaringType != topMethod?.DeclaringType && deepMethod?.DeclaringType?.Namespace == topMethod?.DeclaringType?.Namespace) - { - return deepMethod; - } - } - } - } - catch (Exception) - { - // Ignore exceptions in Release. The code above won't throw, but if it does, we don't want to crash the app. -#if DEBUG - throw; -#endif - } + string fileName = Path.GetFileName(sourceFilePath); - return topMethod; + return $"{fileName}::{memberName}::{sourceLineNumber}"; } } } diff --git a/src/common/ManagedCommon/RunnerHelper.cs b/src/common/ManagedCommon/RunnerHelper.cs index 67ca0856aec2..16ff45428efe 100644 --- a/src/common/ManagedCommon/RunnerHelper.cs +++ b/src/common/ManagedCommon/RunnerHelper.cs @@ -14,12 +14,11 @@ namespace ManagedCommon { public static class RunnerHelper { - public static void WaitForPowerToysRunner(int powerToysPID, Action act) + public static void WaitForPowerToysRunner(int powerToysPID, Action act, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") { var stackTrace = new StackTrace(); var assembly = Assembly.GetCallingAssembly().GetName(); - var callingMethod = stackTrace.GetFrame(1).GetMethod().Name; - PowerToysTelemetry.Log.WriteEvent(new DebugEvent() { Message = $"[{assembly}][{callingMethod}]WaitForPowerToysRunner waiting for Event powerToysPID={powerToysPID}" }); + PowerToysTelemetry.Log.WriteEvent(new DebugEvent() { Message = $"[{assembly}][{memberName}]WaitForPowerToysRunner waiting for Event powerToysPID={powerToysPID}" }); Task.Run(() => { const uint INFINITE = 0xFFFFFFFF; @@ -29,7 +28,7 @@ public static void WaitForPowerToysRunner(int powerToysPID, Action act) IntPtr powerToysProcHandle = NativeMethods.OpenProcess(SYNCHRONIZE, false, powerToysPID); if (NativeMethods.WaitForSingleObject(powerToysProcHandle, INFINITE) == WAIT_OBJECT_0) { - PowerToysTelemetry.Log.WriteEvent(new DebugEvent() { Message = $"[{assembly}][{callingMethod}]WaitForPowerToysRunner Event Notified powerToysPID={powerToysPID}" }); + PowerToysTelemetry.Log.WriteEvent(new DebugEvent() { Message = $"[{assembly}][{memberName}]WaitForPowerToysRunner Event Notified powerToysPID={powerToysPID}" }); act.Invoke(); } }); From 0c03d2c48926bf67ca82323a42d3d157edf74fbe Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Fri, 13 Dec 2024 15:59:46 +0800 Subject: [PATCH 03/11] Use function to init static value --- src/common/ManagedCommon/Logger.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index 04a3f8d3df1c..3d4e6f6d647c 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -15,16 +15,13 @@ namespace ManagedCommon { public static class Logger { - private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); - private static readonly string Version = FileVersionInfo.GetVersionInfo(Path.Combine(System.AppContext.BaseDirectory, ApplicationName)).ProductVersion; - private static readonly string Error = "Error"; private static readonly string Warning = "Warning"; private static readonly string Info = "Info"; private static readonly string Debug = "Debug"; private static readonly string TraceFlag = "Trace"; - private static readonly string ApplicationName = "PowerToys.exe"; + private static readonly string Version = GetVersion(); /// /// Initializes the logger and sets the path for logging. @@ -55,6 +52,25 @@ public static void InitializeLogger(string applicationLogPath, bool isLocalLow = Trace.AutoFlush = true; } + public static string GetVersion() + { + string applicationName = "PowerToys.exe"; + try + { + var versionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(System.AppContext.BaseDirectory, applicationName)); + if (versionInfo != null) + { + return versionInfo.ProductVersion; + } + } + catch (Exception) + { + return "0.0.0.1"; + } + + return "0.0.0.1"; + } + [MethodImpl(MethodImplOptions.NoInlining)] public static void LogError(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { From 925f44c327ed9eefdcab6dd2af529c676da880e1 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Thu, 19 Dec 2024 10:26:43 +0800 Subject: [PATCH 04/11] Replace GetFileName with GetFileNameWithoutExtension --- src/common/ManagedCommon/Logger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index 3d4e6f6d647c..ac348716bb4f 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -144,7 +144,7 @@ private static void Log(string message, string type, string memberName, string s private static string GetCallerInfo(string memberName, string sourceFilePath, int sourceLineNumber) { - string fileName = Path.GetFileName(sourceFilePath); + string fileName = Path.GetFileNameWithoutExtension(sourceFilePath); return $"{fileName}::{memberName}::{sourceLineNumber}"; } From e86fbef2a2e4be96027f8a2478990f6ab7f766cd Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Thu, 19 Dec 2024 10:55:58 +0800 Subject: [PATCH 05/11] Add exception catch for GetCallerInfo --- src/common/ManagedCommon/Logger.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index ac348716bb4f..c6f1454ce7f5 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -144,9 +144,25 @@ private static void Log(string message, string type, string memberName, string s private static string GetCallerInfo(string memberName, string sourceFilePath, int sourceLineNumber) { - string fileName = Path.GetFileNameWithoutExtension(sourceFilePath); + string callerFileName = "Unknown"; - return $"{fileName}::{memberName}::{sourceLineNumber}"; + try + { + string fileNameWithoutEx = Path.GetFileNameWithoutExtension(sourceFilePath); + if (!string.IsNullOrEmpty(fileNameWithoutEx)) + { + callerFileName = fileNameWithoutEx; + } + } + catch (Exception) + { + callerFileName = "Unknown"; +#if DEBUG + throw; +#endif + } + + return $"{callerFileName}::{memberName}::{sourceLineNumber}"; } } } From e0a2758927e489effd18b385482502603bcd2722 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Tue, 24 Dec 2024 15:15:53 +0800 Subject: [PATCH 06/11] Remove sourceLineNumber --- src/common/ManagedCommon/Logger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index c6f1454ce7f5..64a1d3ab461d 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -162,7 +162,7 @@ private static string GetCallerInfo(string memberName, string sourceFilePath, in #endif } - return $"{callerFileName}::{memberName}::{sourceLineNumber}"; + return $"{callerFileName}::{memberName}"; } } } From 5ce827ec0b3235b6cf44c2a8a14311d76b35e30e Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Tue, 24 Dec 2024 16:58:58 +0800 Subject: [PATCH 07/11] Add kernal to allow list --- .github/actions/spell-check/allow/code.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/spell-check/allow/code.txt b/.github/actions/spell-check/allow/code.txt index 8c53e5282757..25f8ab6057f9 100644 --- a/.github/actions/spell-check/allow/code.txt +++ b/.github/actions/spell-check/allow/code.txt @@ -262,3 +262,6 @@ leilzh #Tools OIP + +# SemanticKernal +Kernal From 69244d0e95b65314084c0d2a07c4b27aae0e9118 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Tue, 24 Dec 2024 16:59:46 +0800 Subject: [PATCH 08/11] Remove unused commit --- .github/actions/spell-check/allow/code.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/actions/spell-check/allow/code.txt b/.github/actions/spell-check/allow/code.txt index 25f8ab6057f9..8c53e5282757 100644 --- a/.github/actions/spell-check/allow/code.txt +++ b/.github/actions/spell-check/allow/code.txt @@ -262,6 +262,3 @@ leilzh #Tools OIP - -# SemanticKernal -Kernal From 226c375ed404dc34bc314f22230321ab713a7fc8 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Wed, 8 Jan 2025 16:57:27 +0800 Subject: [PATCH 09/11] Add new folder to place source generation context --- src/common/ManagedCommon/LanguageHelper.cs | 3 ++- .../SourceGenerationContext.cs} | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) rename src/common/ManagedCommon/{ManagedCommonJsonSerializerContext.cs => SerializationContext/SourceGenerationContext.cs} (73%) diff --git a/src/common/ManagedCommon/LanguageHelper.cs b/src/common/ManagedCommon/LanguageHelper.cs index 042e57bd8597..89b48e7ccbc2 100644 --- a/src/common/ManagedCommon/LanguageHelper.cs +++ b/src/common/ManagedCommon/LanguageHelper.cs @@ -6,6 +6,7 @@ using System.IO; using System.Text.Json; using System.Text.Json.Serialization; +using ManagedCommon.Serialization; namespace ManagedCommon { @@ -35,7 +36,7 @@ public static string LoadLanguage() inputStream.Close(); reader.Dispose(); - return JsonSerializer.Deserialize(data, ManagedCommonJsonSerializerContext.Default.OutGoingLanguageSettings).LanguageTag; + return JsonSerializer.Deserialize(data, SourceGenerationContext.Default.OutGoingLanguageSettings).LanguageTag; } catch (Exception) { diff --git a/src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs b/src/common/ManagedCommon/SerializationContext/SourceGenerationContext.cs similarity index 73% rename from src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs rename to src/common/ManagedCommon/SerializationContext/SourceGenerationContext.cs index 56c5d2c362de..24a46f68d9a4 100644 --- a/src/common/ManagedCommon/ManagedCommonJsonSerializerContext.cs +++ b/src/common/ManagedCommon/SerializationContext/SourceGenerationContext.cs @@ -5,9 +5,9 @@ using System.Text.Json.Serialization; using static ManagedCommon.LanguageHelper; -namespace ManagedCommon; +namespace ManagedCommon.Serialization; [JsonSerializable(typeof(OutGoingLanguageSettings))] -internal sealed partial class ManagedCommonJsonSerializerContext : JsonSerializerContext +internal sealed partial class SourceGenerationContext : JsonSerializerContext { } From fbf0a460b30d251a3bc96ad4906031c25980420e Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Mon, 20 Jan 2025 19:29:47 +0800 Subject: [PATCH 10/11] update --- src/common/ManagedCommon/Logger.cs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index 64a1d3ab461d..3d17575bc101 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -21,7 +21,8 @@ public static class Logger private static readonly string Debug = "Debug"; private static readonly string TraceFlag = "Trace"; - private static readonly string Version = GetVersion(); + private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); + private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion; /// /// Initializes the logger and sets the path for logging. @@ -52,32 +53,11 @@ public static void InitializeLogger(string applicationLogPath, bool isLocalLow = Trace.AutoFlush = true; } - public static string GetVersion() - { - string applicationName = "PowerToys.exe"; - try - { - var versionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(System.AppContext.BaseDirectory, applicationName)); - if (versionInfo != null) - { - return versionInfo.ProductVersion; - } - } - catch (Exception) - { - return "0.0.0.1"; - } - - return "0.0.0.1"; - } - - [MethodImpl(MethodImplOptions.NoInlining)] public static void LogError(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { Log(message, Error, memberName, sourceFilePath, sourceLineNumber); } - [MethodImpl(MethodImplOptions.NoInlining)] public static void LogError(string message, Exception ex, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { if (ex == null) @@ -105,31 +85,26 @@ public static void LogError(string message, Exception ex, [System.Runtime.Compil } } - [MethodImpl(MethodImplOptions.NoInlining)] public static void LogWarning(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { Log(message, Warning, memberName, sourceFilePath, sourceLineNumber); } - [MethodImpl(MethodImplOptions.NoInlining)] public static void LogInfo(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { Log(message, Info, memberName, sourceFilePath, sourceLineNumber); } - [MethodImpl(MethodImplOptions.NoInlining)] public static void LogDebug(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { Log(message, Debug, memberName, sourceFilePath, sourceLineNumber); } - [MethodImpl(MethodImplOptions.NoInlining)] public static void LogTrace([System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { Log(string.Empty, TraceFlag, memberName, sourceFilePath, sourceLineNumber); } - [MethodImpl(MethodImplOptions.NoInlining)] private static void Log(string message, string type, string memberName, string sourceFilePath, int sourceLineNumber) { Trace.WriteLine("[" + DateTime.Now.TimeOfDay + "] [" + type + "] " + GetCallerInfo(memberName, sourceFilePath, sourceLineNumber)); From fcc3bbf9b7f719dc425e402a58b99209958238c9 Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Mon, 20 Jan 2025 22:39:32 +0800 Subject: [PATCH 11/11] fix build issue --- src/common/ManagedCommon/Logger.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index 3d17575bc101..c4774d42cff8 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -22,7 +22,15 @@ public static class Logger private static readonly string TraceFlag = "Trace"; private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); + + /* + * Please pay more attention! + * If you want to publish it with Native AOT enabled (or publish as a single file). + * You need to find another way to remove Assembly.Location usage. + */ +#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion; +#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file /// /// Initializes the logger and sets the path for logging.