This commit is contained in:
Калышев Ян 2022-11-21 05:43:41 +04:00
parent 0d60d7ca10
commit 1c4c533ceb
6 changed files with 82 additions and 32 deletions

View File

@ -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}");
}
/// <summary>
/// <summary>
@ -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}");
}
/// <summary>
/// Вывод карты
@ -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}");
}
/// <summary>
/// Перемещение

View File

@ -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)
{

View File

@ -10,20 +10,25 @@
</PropertyGroup>
<ItemGroup>
<None Remove="nlog.config" />
<None Remove="serialog.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="nlog.config">
<EmbeddedResource Include="serialog.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.1.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
</Project>

View File

@ -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<FormMapWithSetBoats>().AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddSingleton<FormMapWithSetBoats>()
.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);
});
}
}
}

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="carlog-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>

View File

@ -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"
}
}
}