diff --git a/KeyAsio.Gui/App.xaml.cs b/KeyAsio.Gui/App.xaml.cs index 87c4b5e..116802a 100644 --- a/KeyAsio.Gui/App.xaml.cs +++ b/KeyAsio.Gui/App.xaml.cs @@ -21,6 +21,9 @@ using KeyAsio.Shared.Realtime; using KeyAsio.Shared.Utils; using Milki.Extensions.Configuration; +using Milki.Extensions.MixPlayer; +using NLog.Extensions.Logging; + using OrtdpLogger = KeyAsio.MemoryReading.Logger; namespace KeyAsio.Gui; @@ -144,6 +147,10 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc private void App_OnStartup(object sender, StartupEventArgs e) { + Configuration.Instance.SetLogger( + Microsoft.Extensions.Logging.LoggerFactory.Create(k => k.AddNLog("nlog.config"))); + NLogDevice.RegisterDefault(); + UiDispatcher.SetUiSynchronizationContext(new DispatcherSynchronizationContext()); Dispatcher.UnhandledException += Dispatcher_UnhandledException; var settings = ConfigurationFactory.GetConfiguration(MyYamlConfigurationConverter.Instance, "."); diff --git a/KeyAsio.Gui/Utils/NLogDevice.cs b/KeyAsio.Gui/Utils/NLogDevice.cs new file mode 100644 index 0000000..74082e4 --- /dev/null +++ b/KeyAsio.Gui/Utils/NLogDevice.cs @@ -0,0 +1,40 @@ +using ATL.Logging; +using KeyAsio.Shared; +using ILogger = KeyAsio.MemoryReading.Logging.ILogger; +using LogLevel = KeyAsio.MemoryReading.Logging.LogLevel; + +namespace KeyAsio.Gui.Utils; + +internal class NLogDevice : ILogDevice +{ + private static Log _logInstance = new(); + + private static readonly ILogger Logger = LogUtils.GetLogger("ATL"); + public static ILogDevice Instance { get; } = new NLogDevice(); + + public static void RegisterDefault() + { + LogDelegator.SetLog(ref _logInstance); + _logInstance.Register(Instance); + } + + private NLogDevice() + { + _logInstance.Register(this); + } + + public void DoLog(Log.LogItem anItem) + { + var level = GetLevel(anItem.Level); + Logger.Log(level, $"({anItem.Location}) {anItem.Message}"); + } + + private static LogLevel GetLevel(int level) + { + if (level == Log.LV_DEBUG) return LogLevel.Debug; + if (level == Log.LV_INFO) return LogLevel.Information; + if (level == Log.LV_WARNING) return LogLevel.Warning; + if (level == Log.LV_ERROR) return LogLevel.Error; + return LogLevel.Information; + } +} \ No newline at end of file