From 5648f6a74190130050ef18f0851c7a2d213d520e Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 16 Apr 2021 12:43:05 +0200 Subject: [PATCH] - initialize logging --- Mystify/App.axaml.cs | 25 +++++++++++++++++++- Mystify/Bootstrapper.cs | 1 + Mystify/Installers/LoggingInstaller.cs | 32 ++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Mystify/Installers/LoggingInstaller.cs diff --git a/Mystify/App.axaml.cs b/Mystify/App.axaml.cs index 539c55c..0347028 100644 --- a/Mystify/App.axaml.cs +++ b/Mystify/App.axaml.cs @@ -7,6 +7,10 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Lib.Logging.Factories; +using Lib.Logging.Interfaces; +using Lib.Logging.Loggers.Factories; +using Lib.Logging.Loggers.Interfaces; using Lib.NotifyIcon; using LightweightIocContainer.Interfaces; using Mystify.ViewModels; @@ -18,7 +22,12 @@ namespace Mystify public class App : Application { private IIocContainer? _kernel; + + private ILog? _log; + private ILoggerInitializer? _loggerInitializer; + private INotifyIcon? _notifyIcon; + private MainWindow? _mainWindow; private MainWindowViewModel? _mainWindowViewModel; @@ -30,6 +39,13 @@ namespace Mystify Bootstrapper bootstrapper = new(); _kernel = bootstrapper.BootstrapKernel(); + + ILogFactory logFactory = _kernel.Resolve(); + _log = logFactory.Create(); + + ILoggerInitializerFactory loggerInitializerFactory = _kernel.Resolve(); + _loggerInitializer = loggerInitializerFactory.Create(_log); + _loggerInitializer.Init(); MainModel mainModel = _kernel.Resolve(); _mainWindow = new MainWindow(); @@ -68,10 +84,17 @@ namespace Mystify _mainWindow?.Show(); } - private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs args) + private async void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs args) //TODO: return Task? { _mainWindow?.Close(); _notifyIcon?.Remove(); + + if (_log != null) + await _log.DisposeAsync(); + + if (_loggerInitializer != null) + await _loggerInitializer.DisposeAsync(); + _kernel?.Dispose(); } } diff --git a/Mystify/Bootstrapper.cs b/Mystify/Bootstrapper.cs index 7d36272..f861c73 100644 --- a/Mystify/Bootstrapper.cs +++ b/Mystify/Bootstrapper.cs @@ -15,6 +15,7 @@ namespace Mystify new MainInstaller(), new AudioInstaller(), new DriverInstaller(), + new LoggingInstaller(), new MidiInstaller(), new NotifyIconInstaller()); } diff --git a/Mystify/Installers/LoggingInstaller.cs b/Mystify/Installers/LoggingInstaller.cs new file mode 100644 index 0000000..5977e2b --- /dev/null +++ b/Mystify/Installers/LoggingInstaller.cs @@ -0,0 +1,32 @@ +// Author: Gockner, Simon +// Created: 2021-04-16 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using Lib.Logging; +using Lib.Logging.Factories; +using Lib.Logging.Interfaces; +using Lib.Logging.Loggers; +using Lib.Logging.Loggers.Factories; +using Lib.Logging.Loggers.Interfaces; +using LightweightIocContainer.Interfaces; +using LightweightIocContainer.Interfaces.Installers; + +namespace Mystify.Installers +{ + public class LoggingInstaller : IIocInstaller + { + public void Install(IIocContainer container) + { + container.Register(); + container.Register(); + container.Register(); + container.Register(); + + //factories + container.RegisterFactory(); + container.RegisterFactory(); + container.RegisterFactory(); + container.RegisterFactory(); + } + } +} \ No newline at end of file