изменения логирования

This commit is contained in:
Hells Hound 2022-11-28 12:13:37 +04:00
parent 47b268ae21
commit 4dbe6d880b
5 changed files with 73 additions and 7 deletions

View File

@ -8,12 +8,26 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="jsconfig.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="jsconfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" 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.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" 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.Settings.Delegates" Version="1.0.0" />

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AircraftCarrier
{
internal class EntityAircraftCarrier : EntityWarship
public class EntityAircraftCarrier : EntityWarship
{
/// <summary>
/// Дополнительный цвет

View File

@ -145,8 +145,8 @@ namespace AircraftCarrier
DrawingObjectWarship warship = new(drawningWarship);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warship >= 0)
{
_logger.LogInformation($"Добавлен объект {warship}");
MessageBox.Show("Объект добавлен");
_logger.LogInformation("Добавлен объект {@Airplane}", warship);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
@ -180,8 +180,8 @@ namespace AircraftCarrier
var deletedWarship = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
if (deletedWarship != null)
{
_logger.LogInformation($"Объект {deletedWarship} удалён");
MessageBox.Show("Объект удален");
_logger.LogInformation("Из текущей карты удален объект {@ship}", deletedWarship);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else

View File

@ -1,9 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Serilog;
using System.ServiceProcess;
namespace AircraftCarrier
{
@ -31,9 +29,15 @@ namespace AircraftCarrier
services.AddSingleton<FormMapWithSetWarships>()
.AddLogging(option =>
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "jsconfig.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration()
.WriteTo.File("Log.txt")
.CreateLogger();
.ReadFrom.Configuration(configuration)
.CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);

View File

@ -0,0 +1,48 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Destructure": [
{
"Name": "ByTransforming",
"Args": {
"returnType": "AircraftCarrier.EntityWarship",
"transformation": "r => new { BodyColor = r.BodyColor.Name, r.Speed, r.Weight }"
}
},
{
"Name": "ByTransforming",
"Args": {
"returnType": "AircraftCarrier.EntityAircraftCarrier",
"transformation": "r => new { BodyColor = r.BodyColor.Name, DopColor = r.DopColor, r.BodyKit, r.Сabin, r.SuperEngine, r.Speed, r.Weight }"
}
},
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 4 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 100 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 10 }
}
],
"Properties": {
"Application": "AircraftCarrier"
}
}
}