From ff6ce298cd7da8ecc460aa0463060f8b5bde909b Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 20 Nov 2022 13:05:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AntiAircraftGun/AntiAircraftGun.csproj | 18 +++++++++++++++++ .../FormMapWithSetAntiAircraftGuns.cs | 11 ++++++++-- AntiAircraftGun/AntiAircraftGun/Program.cs | 20 ++++++++++++++++++- AntiAircraftGun/AntiAircraftGun/nlog.config | 13 ++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 AntiAircraftGun/AntiAircraftGun/nlog.config diff --git a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj index 13ee123..3eb1f1d 100644 --- a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj +++ b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj @@ -8,6 +8,24 @@ enable + + + + + + + Always + + + + + + + + + + + True diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs index 428b465..417275c 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -24,11 +25,16 @@ namespace AntiAircraftGun /// Объект от коллекции карт /// private readonly MapsCollection _mapsCollection; + /// + /// Логер + /// + private readonly ILogger _logger; /// Конструктор /// - public FormMapWithSetAntiAircraftGuns() + public FormMapWithSetAntiAircraftGuns(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -75,6 +81,7 @@ namespace AntiAircraftGun } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } /// /// Выбор карты diff --git a/AntiAircraftGun/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index ce76065..f03c116 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace AntiAircraftGun { internal static class Program @@ -11,7 +15,21 @@ namespace AntiAircraftGun // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetAntiAircraftGuns()); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + { + Application.Run(serviceProvider.GetRequiredService()); + } + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddSingleton() + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); } } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/nlog.config b/AntiAircraftGun/AntiAircraftGun/nlog.config new file mode 100644 index 0000000..6d5e25e --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file