diff --git a/Boats/Boats/Boats.csproj b/Boats/Boats/Boats.csproj index 13ee123..3eb1f1d 100644 --- a/Boats/Boats/Boats.csproj +++ b/Boats/Boats/Boats.csproj @@ -8,6 +8,24 @@ enable + + + + + + + Always + + + + + + + + + + + True diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs index 5c4fb06..5a9cf3c 100644 --- a/Boats/Boats/FormMapWithSetBoats.cs +++ b/Boats/Boats/FormMapWithSetBoats.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -25,6 +26,7 @@ namespace Boats /// Объект от коллекции карт /// private readonly MapsCollection _mapsCollection; + private readonly ILogger _logger; /// /// Объект от класса карты с набором объектов /// @@ -32,9 +34,10 @@ namespace Boats /// /// Конструктор /// - public FormMapWithSetBoats() + public FormMapWithSetBoats(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); ComboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -223,6 +226,7 @@ namespace Boats } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[ComboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } /// /// Удаление карты diff --git a/Boats/Boats/Program.cs b/Boats/Boats/Program.cs index 91dda50..d6eed69 100644 --- a/Boats/Boats/Program.cs +++ b/Boats/Boats/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace Boats { internal static class Program @@ -11,7 +15,21 @@ namespace Boats // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetBoats()); + 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/Boats/Boats/nlog.config b/Boats/Boats/nlog.config new file mode 100644 index 0000000..9338255 --- /dev/null +++ b/Boats/Boats/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file