45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
using System.ComponentModel;
|
|
using System.Configuration;
|
|
using Livia.Utility.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Livia.Properties;
|
|
|
|
// This class allows you to handle specific events on the settings class:
|
|
// The SettingChanging event is raised before a setting's value is changed.
|
|
// The PropertyChanged event is raised after a setting's value is changed.
|
|
// The SettingsLoaded event is raised after the setting values are loaded.
|
|
// The SettingsSaving event is raised before the setting values are saved.
|
|
public static class SettingsLogger
|
|
{
|
|
private static ILogger? _logger;
|
|
|
|
public static void Init()
|
|
{
|
|
_logger = ActivatorUtilities.GetServiceOrCreateInstance<ILogger>(ServiceProviderFactory.ServiceProvider);
|
|
// To add event handlers for saving and changing settings, uncomment the lines below:
|
|
Settings.Default.SettingChanging += SettingChangingEventHandler;
|
|
Settings.Default.SettingsSaving += SettingsSavingEventHandler;
|
|
|
|
/*
|
|
ViewSettings.Default.SettingChanging += SettingChangingEventHandler;
|
|
ViewSettings.Default.SettingsSaving += SettingsSavingEventHandler;
|
|
*/
|
|
}
|
|
|
|
|
|
private static void SettingChangingEventHandler(object sender, SettingChangingEventArgs e)
|
|
{
|
|
// Add code to handle the SettingChangingEvent event here.
|
|
_logger?.LogInformation("Changing setting for {SettingName} from {sender} to {NewValue}", e.SettingName, sender, e.NewValue);
|
|
}
|
|
|
|
|
|
|
|
private static void SettingsSavingEventHandler(object sender, CancelEventArgs e)
|
|
{
|
|
_logger?.LogInformation("Saving settings for {sender}", sender);
|
|
}
|
|
|
|
} |