Лабораторная работа №7 (ну оно вроде работает с JSON, но не XML)
This commit is contained in:
parent
1e1053b0af
commit
f704b0e156
@ -279,12 +279,13 @@ public partial class FormCleaningCarCollection : Form
|
|||||||
{
|
{
|
||||||
listBoxCollection.Items.Add(collection);
|
listBoxCollection.Items.Add(collection);
|
||||||
}
|
}
|
||||||
|
_logger.LogInformation("Загрузка из файла: {filename}", saveFileDialog.FileName);
|
||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
|
||||||
@ -31,13 +31,15 @@ namespace ProjectCleaningCar
|
|||||||
{
|
{
|
||||||
services
|
services
|
||||||
.AddSingleton<FormCleaningCarCollection>()
|
.AddSingleton<FormCleaningCarCollection>()
|
||||||
.AddLogging(option => {
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
option.SetMinimumLevel(LogLevel.Information);
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
//option.AddSerilog(new LoggerConfiguration()
|
var config = new ConfigurationBuilder()
|
||||||
// //.WriteTo
|
.AddJsonFile("C://Users//ipazu//Desktop//OOP_LABS//ProjectCleaningCar//ProjectCleaningCar//serilogConfig.json", optional: false, reloadOnChange: true)
|
||||||
|
.Build();
|
||||||
// .CreateLogger());
|
option.AddSerilog(Log.Logger = new LoggerConfiguration()
|
||||||
option.AddNLog("serilog.config");
|
.ReadFrom.Configuration(config)
|
||||||
|
.CreateLogger());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,9 +9,16 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -30,7 +37,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="serilog.config">
|
<None Update="serilogConfig.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
<appSettings>
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<add key="serilog:minimum-level" value="Verbose"/>
|
||||||
autoReload="true" internalLogLevel="Info">
|
<add key="serilog:write-to:LiterateConsole"/>
|
||||||
<targets>
|
</appSettings>
|
||||||
<target xsi:type="File" name="tofile" fileName="carlog-${shortdate}.log" />
|
|
||||||
</targets>
|
|
||||||
<rules>
|
|
||||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
|
||||||
</rules>
|
|
||||||
</nlog>
|
|
||||||
</configuration>
|
</configuration>
|
24
ProjectCleaningCar/ProjectCleaningCar/serilogConfig.json
Normal file
24
ProjectCleaningCar/ProjectCleaningCar/serilogConfig.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ],
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"System": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
|
||||||
|
"WriteTo": [
|
||||||
|
{ "Name": "Console" },
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "C:\\Users\\ipazu\\Desktop\\log.txt",
|
||||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Message}{NewLine:1}{Exception:1}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user