diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index 13ee123..5fdb94b 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -8,6 +8,13 @@ enable + + + + + + + True diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 98043b9..8508069 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) @@ -77,6 +82,7 @@ namespace Airbus _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } //Выбор карты @@ -122,8 +128,6 @@ namespace Airbus //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { - //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ ВСТАВКИ - var formPlaneConfig = new FormPlaneConfig(); formPlaneConfig.AddEvent(AddPlane); @@ -132,8 +136,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..883ead7 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