diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index f1f241bff2..a6eda438b4 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -44,6 +44,7 @@ using MaaWpfGui.Services; using MaaWpfGui.Services.Notification; using MaaWpfGui.Services.Web; using MaaWpfGui.States; +using MaaWpfGui.Utilities; using MaaWpfGui.ViewModels.UI; using MaaWpfGui.ViewModels.UserControl.TaskQueue; using Newtonsoft.Json; @@ -463,7 +464,7 @@ public class AsstProxy /// 是否成功。 public bool LoadResource() { - _logger.Information("Load Resource"); + using var log = new LogScope(_logger); string clientType = SettingsViewModel.GameSettings.ClientType; diff --git a/src/MaaWpfGui/Utilities/LogScope.cs b/src/MaaWpfGui/Utilities/LogScope.cs new file mode 100644 index 0000000000..0635361a0b --- /dev/null +++ b/src/MaaWpfGui/Utilities/LogScope.cs @@ -0,0 +1,39 @@ +// +// Part of the MaaWpfGui project, maintained by the MaaAssistantArknights team (Maa Team) +// Copyright (C) 2021-2025 MaaAssistantArknights Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License v3.0 only as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY +// +#nullable enable +using System; +using System.Runtime.CompilerServices; +using Serilog; + +namespace MaaWpfGui.Utilities; + +public class LogScope : IDisposable +{ + private readonly ILogger _logger; + private readonly string _methodName; + private readonly System.Diagnostics.Stopwatch _stopwatch; + + public LogScope(ILogger logger, [CallerMemberName] string methodName = "") + { + _logger = logger; + _methodName = methodName; + _stopwatch = System.Diagnostics.Stopwatch.StartNew(); + _logger.Information("{MethodName} Enter", _methodName); + } + + void IDisposable.Dispose() + { + _stopwatch.Stop(); + _logger.Information("{MethodName} Exit, {Elapsed:#,0} ms", _methodName, _stopwatch.ElapsedMilliseconds); + } +} diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs index 71d4220cbd..632c87d0bd 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs @@ -715,7 +715,7 @@ public class FightSettingsUserControlModel : TaskSettingsViewModel, FightSetting public void UpdateStageList() { Execute.PostToUIThreadAsync(() => { - _logger.Information("Updating stage list..."); + using var log = new LogScope(_logger); using var scope = _lock.EnterScope(); var stageList = Instances.StageManager.GetStageList(); RefreshStageList();