From c846489b7cda9d08184fdb606abca03e03de44f0 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 12:54: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.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 18 ++++++++++++++++++ Airbus/Airbus/FormMapWithSetPlanes.cs | 15 ++++++++------- Airbus/Airbus/Program.cs | 23 ++++++++++++++++++++++- Airbus/Airbus/nlog.config | 15 +++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 Airbus/Airbus/nlog.config diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index 3ec74d3..c22bcea 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -8,6 +8,16 @@ enable + + + + + + + Always + + + True @@ -28,4 +38,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index b8e7bed..a2ac496 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; @@ -24,10 +25,14 @@ namespace Airbus //объект от коллекции карт private readonly MapsCollection _mapsCollection; + //логер + private readonly ILogger _logger; + //конструктор - public FormMapWithSetPlanes() + public FormMapWithSetPlanes(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var element in _mapsDict) @@ -78,6 +83,7 @@ namespace Airbus _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } //Выбор карты @@ -117,14 +123,11 @@ namespace Airbus { MessageBox.Show("Не удалось добавить объект"); } - } //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { - //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ ВСТАВКИ - var formPlaneConfig = new FormPlaneConfig(); formPlaneConfig.AddEvent(AddPlane); @@ -134,8 +137,6 @@ namespace Airbus //удаление объекта private void ButtonRemovePlane_Click(object sender, EventArgs e) { - //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ УДАЛЕНИЯ - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 5166800..5dc32b1 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,24 @@ 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..02f005b --- /dev/null +++ b/Airbus/Airbus/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file