Skip to content

Commit 775dd94

Browse files
committed
ログの出力
1 parent cf8cddc commit 775dd94

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

WindowTranslator/Modules/Main/MainWindowModule.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Kamishibai;
22
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Logging;
34
using Microsoft.Extensions.Options;
45
using Microsoft.VisualStudio.Threading;
56
using System.Collections.ObjectModel;
@@ -10,10 +11,11 @@
1011

1112
namespace WindowTranslator.Modules.Main;
1213

13-
public sealed class MainWindowModule(App app, IServiceProvider provider) : IMainWindowModule, IDisposable
14+
public sealed class MainWindowModule(App app, IServiceProvider provider, ILogger<MainWindowModule> logger) : IMainWindowModule, IDisposable
1415
{
1516
private readonly App app = app;
1617
private readonly IServiceProvider provider = provider;
18+
private readonly ILogger<MainWindowModule> logger = logger;
1719
private readonly AsyncSemaphore asyncLock = new(1);
1820

1921
public ObservableCollection<WindowInfo> OpenedWindows { get; } = new();
@@ -34,6 +36,7 @@ public Task OpenTargetAsync(IntPtr targetWindowHandle, string name)
3436
var validationResults = await validators.ValidateAsync(settings);
3537
if (validationResults.IsEmpty())
3638
{
39+
this.logger.LogInformation($"Settings for target '{name}' are valid.");
3740
return settings;
3841
}
3942

@@ -48,10 +51,13 @@ public Task OpenTargetAsync(IntPtr targetWindowHandle, string name)
4851
switch (result)
4952
{
5053
case Wpf.Ui.Controls.MessageBoxResult.Primary:
54+
this.logger.LogInformation($"User chose to open settings for target '{name}'.");
5155
break;
5256
case Wpf.Ui.Controls.MessageBoxResult.Secondary:
57+
this.logger.LogWarning($"Settings for target '{name}' are invalid, but user chose to run as is.");
5358
return settings;
5459
default:
60+
this.logger.LogWarning($"Settings for target '{name}' are invalid, and user cancelled the operation.");
5561
return null;
5662
}
5763
}

WindowTranslator/Modules/Settings/AllSettingsViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Kamishibai;
1111
using Microsoft.Extensions.Configuration;
1212
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Logging;
1314
using Microsoft.Extensions.Options;
1415
using Microsoft.Win32;
1516
using PropertyTools.DataAnnotations;
@@ -46,6 +47,7 @@ sealed partial class AllSettingsViewModel : ObservableObject, IDisposable
4647
private readonly IAutoTargetStore autoTargetStore;
4748
private readonly IEnumerable<ITargetSettingsValidator> validators;
4849
private readonly IMainWindowModule mainWindowModule;
50+
private readonly ILogger<AllSettingsViewModel> logger;
4951
private readonly IConfigurationRoot? rootConfig;
5052
private readonly string target;
5153
[ObservableProperty]
@@ -109,6 +111,7 @@ public AllSettingsViewModel(
109111
[Inject] IConfiguration config,
110112
[Inject] IEnumerable<ITargetSettingsValidator> validators,
111113
[Inject] IMainWindowModule mainWindowModule,
114+
[Inject] ILogger<AllSettingsViewModel> logger,
112115
string target,
113116
bool? applyMode = null)
114117
{
@@ -147,6 +150,7 @@ public AllSettingsViewModel(
147150
this.autoTargetStore = autoTargetStore;
148151
this.validators = validators;
149152
this.mainWindowModule = mainWindowModule;
153+
this.logger = logger;
150154
this.target = target;
151155
this.rootConfig = config as IConfigurationRoot;
152156
this.updateChecker.UpdateAvailable += UpdateChecker_UpdateAvailable;
@@ -277,6 +281,7 @@ public async Task SaveAsync(object window)
277281
{
278282
return;
279283
}
284+
this.logger.LogWarning("Settings are invalid, but user chose to save them anyway.");
280285
}
281286

282287
// 値の保存

0 commit comments

Comments
 (0)