diff --git a/WatchList.Core/Logger/AggregateLogging.cs b/WatchList.Core/Logger/AggregateLogging.cs new file mode 100644 index 00000000..953f7705 --- /dev/null +++ b/WatchList.Core/Logger/AggregateLogging.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Logging; + +namespace WatchList.Core.Logger +{ + public class AggregateLogging : List, ILogger + { + private readonly LogLevel _logLevel; + + public AggregateLogging() + : base() + { + } + + public AggregateLogging(int capacity) + : base(capacity) + { + } + + public AggregateLogging(IEnumerable collection) + : base(collection) + { + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + { + foreach (var loggin in this) + { + loggin.Log(logLevel, eventId, state, exception, formatter); + } + } + + public bool IsEnabled(LogLevel logLevel) => _logLevel <= logLevel; + + public IDisposable? BeginScope(TState state) + where TState : notnull + => new Disposable(); + + private sealed class Disposable : IDisposable + { + public void Dispose() + { + } + } + } +} diff --git a/WatchList.WinForms/BoxCinemaForm.Designer.cs b/WatchList.WinForms/BoxCinemaForm.Designer.cs index 3301656b..d5123b88 100644 --- a/WatchList.WinForms/BoxCinemaForm.Designer.cs +++ b/WatchList.WinForms/BoxCinemaForm.Designer.cs @@ -610,7 +610,7 @@ private void InitializeComponent() Name = "BoxCinemaForm"; StartPosition = FormStartPosition.CenterScreen; Text = "BoxCinema"; - FormClosed += BoxCinemaForm_FormClosed; + FormClosing += BoxCinemaForm_FormClosing; ((System.ComponentModel.ISupportInitialize)cinemaBindingSource).EndInit(); ((System.ComponentModel.ISupportInitialize)dgvCinema).EndInit(); ((System.ComponentModel.ISupportInitialize)filterModelBindingSource).EndInit(); diff --git a/WatchList.WinForms/BoxCinemaForm.cs b/WatchList.WinForms/BoxCinemaForm.cs index f462f08d..0819be91 100644 --- a/WatchList.WinForms/BoxCinemaForm.cs +++ b/WatchList.WinForms/BoxCinemaForm.cs @@ -185,9 +185,9 @@ private void BtnDownloadDataFile_Click(object sender, EventArgs e) UpdateGridData(); } - private void BoxCinemaForm_FormClosed(object sender, FormClosedEventArgs e) + private void BoxCinemaForm_FormClosing(object sender, FormClosingEventArgs e) { - _logger.LogInformation("Close App."); + _logger.LogTrace("Close App."); } private void BtnBackPage_Click(object sender, EventArgs e) diff --git a/WatchList.WinForms/Program.cs b/WatchList.WinForms/Program.cs index 88c96a6d..22b57708 100644 --- a/WatchList.WinForms/Program.cs +++ b/WatchList.WinForms/Program.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging; using WatchList.Core.Logger; using WatchList.Core.Repository; +using WatchList.Core.Repository.Db; using WatchList.Core.Service; using WatchList.Core.Service.Component; using WatchList.Core.Service.DataLoading; @@ -32,14 +33,17 @@ public static void Main() .AddSingleton(new FileDbContextFactory("app.db")) .AddScoped(e => e.GetRequiredService().Create()) .AddScoped() - .AddScoped() + .AddScoped(e => new WatchItemRepository(e.GetRequiredService(), e.GetRequiredService())) .AddScoped() .AddScoped() .AddScoped() .AddTransient() .AddTransient() - .AddTransient(e => new ConsoleLogger(LogLevel.Information)) - .AddTransient(e => new FileLogger(LogLevel.Trace, path)); + .AddSingleton(e => new ConsoleLogger(LogLevel.Information)) + .AddSingleton(e => new FileLogger(LogLevel.Trace, path)) + .AddSingleton(e => e.GetRequiredService()) + .AddSingleton(e => e.GetRequiredService()) + .AddSingleton(e => new AggregateLogging() { e.GetRequiredService(), e.GetRequiredService() }); using var contain = serviceCollection.BuildServiceProvider(new ServiceProviderOptions {