From 70543c40c7e55774dee6459ae54b579a4186df15 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Fri, 25 Nov 2022 16:18:49 +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.=20=D0=A1=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 17 +++++++++++++++++ Airbus/Airbus/FormMapWithSetPlanes.cs | 8 ++++++-- Airbus/Airbus/Program.cs | 19 ++++++++++++++++++- Airbus/Airbus/nlog.config | 13 +++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 Airbus/Airbus/nlog.config diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index 13ee123..90645bb 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -8,6 +8,23 @@ enable + + + + + + + Always + + + + + + + + + + True diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 71f8274..7b1afab 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -28,9 +29,11 @@ namespace Airbus /// /// Конструктор /// - public FormMapWithSetPlanes() + private readonly ILogger _logger; + public FormMapWithSetPlanes(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -78,6 +81,7 @@ namespace Airbus _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } /// /// Выбор карты diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 5166800..b0ef970 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace Airbus { internal static class Program @@ -11,7 +15,20 @@ namespace Airbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetPlanes()); + 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/Airbus/Airbus/nlog.config b/Airbus/Airbus/nlog.config new file mode 100644 index 0000000..ce63bd2 --- /dev/null +++ b/Airbus/Airbus/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file