diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs index 52af911..34fcc89 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs @@ -100,8 +100,8 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); ReloadMaps(); + _logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem}"); } - _logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem}"); } /// /// @@ -114,7 +114,6 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base var formBoatConfig = new FormBoatConfig(); formBoatConfig.AddEvent(AddBoat); formBoatConfig.Show(); - _logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem}"); } private void AddBoat(DrawningBoat drawingBoats) { @@ -129,12 +128,12 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - _logger.LogInformation($"В карту {_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty]} добавлен объект {boat.GetInfo()}"); + _logger.LogInformation($"В карту {listBoxMaps.SelectedItem} добавлен объект {boat.GetInfo()}"); } else { MessageBox.Show("Невозможно добавить объект"); - _logger.LogInformation($"Невозможно добавить объект {boat.GetInfo()} в карту {_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty]}"); + _logger.LogInformation($"Невозможно добавить объект {boat.GetInfo()} в карту {listBoxMaps.SelectedItem}"); } } catch (StorageOverflowException ex) { @@ -175,12 +174,12 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { MessageBox.Show("Объект удален"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - _logger.LogInformation($"Из карты {_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty]} удален объект {boat.GetInfo()}"); + _logger.LogInformation($"Из карты {listBoxMaps.SelectedItem} удален объект {boat.GetInfo()}"); } else { MessageBox.Show("Не удалось удалить объект"); - _logger.LogInformation($"Невозможно удалить объект {boat.GetInfo()} в карту {_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty]}"); + _logger.LogInformation($"Невозможно удалить объект {boat.GetInfo()} в карту {listBoxMaps.SelectedItem}"); } } catch (BoatNotFoundException ex) { @@ -204,7 +203,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base return; } pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - _logger.LogInformation($"Показана гавань для карты {_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty]}"); + _logger.LogInformation($"Показана гавань для карты {listBoxMaps.SelectedItem}"); } /// /// Вывод карты @@ -218,7 +217,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base return; } pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); - _logger.LogInformation($"Показана карта {_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty]}"); + _logger.LogInformation($"Показана карта {listBoxMaps.SelectedItem}"); } /// /// Перемещение diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapsCollection.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapsCollection.cs index f8165d9..b7ae631 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapsCollection.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapsCollection.cs @@ -103,7 +103,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base using (FileStream fs = new(filename, FileMode.Create)) using (StreamWriter sw = new StreamWriter(fs)) { - sw.WriteLine($"MapsCollection{Environment.NewLine}"); + sw.WriteLine($"MapsCollection"); foreach (var storage in _mapStorages) { sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}"); @@ -125,7 +125,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { string str; int count = 0; - while ((str = sr.ReadLine()) != null) + while ((str = sr.ReadLine()) != null && str != "") { if (count == 0) { diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.csproj b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.csproj index 4a22195..d422f99 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.csproj +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.csproj @@ -10,20 +10,25 @@ - + - + Always + + + + + \ No newline at end of file diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs index bb3e731..baf31e3 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs @@ -1,7 +1,7 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; -using System.ServiceProcess; +using Serilog; namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { @@ -25,11 +25,22 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base } private static void ConfigureServices(ServiceCollection services) { - services.AddSingleton().AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); + services.AddSingleton() + .AddLogging(option => + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(path: "serialog.json", optional: false, reloadOnChange: true) + .Build(); + + var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); + }); } + } } \ No newline at end of file diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/nlog.config b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/nlog.config deleted file mode 100644 index 6d5e25e..0000000 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/serialog.json b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/serialog.json new file mode 100644 index 0000000..d4cda71 --- /dev/null +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/serialog.json @@ -0,0 +1,48 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "{Message:lj}: [{Level:u4}]{Timestamp:HH:mm:ss.fff}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "Destructure": [ + { + "Name": "ByTransforming", + "Args": { + "returnType": "PIbd_22_Kalyshev_Y_V_MotorBoat_Base.EntityBoat", + "transformation": "r => new {r.Speed, r.Weight, BodyColor = r.BodyColor.Name }" + } + }, + { + "Name": "ByTransforming", + "Args": { + "returnType": "PIbd_22_Kalyshev_Y_V_MotorBoat_Base.EntitySpeedboat", + "transformation": "r => new {r.Speed, r.Weight, BodyColor = r.BodyColor.Name, DopColor = r.DopColor.Name, r.bodyKit, r.wing, r.sportLine }" + } + }, + { + "Name": "ToMaximumDepth", + "Args": { "maximumDestructuringDepth": 4 } + }, + { + "Name": "ToMaximumStringLength", + "Args": { "maximumStringLength": 100 } + }, + { + "Name": "ToMaximumCollectionCount", + "Args": { "maximumCollectionCount": 10 } + } + ], + "Properties": { + "Application": "PIbd_22_Kalyshev_Y_V_MotorBoat_Base" + } + } +} \ No newline at end of file