From f53ee640bcddcd2fe498bd58173f3b481f9940e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Fri, 2 Dec 2022 18:45:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BB=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 --- .../AirPlaneWithRadar.csproj | 17 ++++++++++++++ .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 9 +++++--- .../AirPlaneWithRadar/Program.cs | 23 ++++++++++++++++++- .../AirPlaneWithRadar/nlog.config | 15 ++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/nlog.config diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/AirPlaneWithRadar.csproj b/AirPlaneWithRadar/AirPlaneWithRadar/AirPlaneWithRadar.csproj index 13ee123..5e3bef9 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/AirPlaneWithRadar.csproj +++ b/AirPlaneWithRadar/AirPlaneWithRadar/AirPlaneWithRadar.csproj @@ -8,6 +8,23 @@ enable + + + + + + + Always + + + + + + + + + + True diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 5a14af4..b70561b 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -17,10 +18,11 @@ namespace AirPlaneWithRadar { "Простая карта", new SimpleMap()},{"Карта с большими коробками", new UserMap_BigBox()},{"Карта со стенами", new UserMap_Colums()} }; private readonly MapsCollection _mapsCollection; - - public FormMapWithSetPlains() + private readonly ILogger _logger; + public FormMapWithSetPlains(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -62,6 +64,7 @@ namespace AirPlaneWithRadar } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"{textBoxNewMapName}"); } private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/Program.cs b/AirPlaneWithRadar/AirPlaneWithRadar/Program.cs index 8cb6b9c..d26028a 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/Program.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace AirPlaneWithRadar { internal static class Program @@ -11,7 +16,23 @@ namespace AirPlaneWithRadar // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetPlains()); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + { + Application.Run(serviceProvider.GetRequiredService < FormMapWithSetPlains>()); + } } + + 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/AirPlaneWithRadar/AirPlaneWithRadar/nlog.config b/AirPlaneWithRadar/AirPlaneWithRadar/nlog.config new file mode 100644 index 0000000..5c71e85 --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file