diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs index f909dc6..8557bf5 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -25,13 +26,19 @@ namespace WarmlyShip /// Объект от коллекции карт /// private readonly MapsCollection _mapsCollection; - + + /// + /// Логер + /// + private readonly ILogger _logger; + /// /// Конструктор /// - public FormMapWithSetWarmlyShip() + public FormMapWithSetWarmlyShip(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox1.Width, pictureBox1.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -78,6 +85,7 @@ namespace WarmlyShip } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } /// /// Выбор карты diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index e3b8eb1..1b05656 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace WarmlyShip { internal static class Program @@ -11,7 +15,24 @@ namespace WarmlyShip // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetWarmlyShip()); + + 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/WarmlyShip/WarmlyShip/WarmlyShip.csproj b/WarmlyShip/WarmlyShip/WarmlyShip.csproj index 13ee123..28f845c 100644 --- a/WarmlyShip/WarmlyShip/WarmlyShip.csproj +++ b/WarmlyShip/WarmlyShip/WarmlyShip.csproj @@ -8,6 +8,23 @@ enable + + + + + + + Always + + + + + + + + + + True diff --git a/WarmlyShip/WarmlyShip/nlog.config b/WarmlyShip/WarmlyShip/nlog.config new file mode 100644 index 0000000..3f0b87b --- /dev/null +++ b/WarmlyShip/WarmlyShip/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file