Добавлены фильтры для логгирования в разные файлы

This commit is contained in:
Данияр Аглиуллов 2022-10-30 04:17:17 +04:00
parent 2fca625262
commit 25e6f2df67
2 changed files with 49 additions and 5 deletions

View File

@ -25,7 +25,9 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Serilog" Version="2.12.0" /> <PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" /> <PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Filters.Expressions" Version="2.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Settings.Delegates" Version="1.0.0" /> <PackageReference Include="Serilog.Settings.Delegates" Version="1.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

View File

@ -1,14 +1,56 @@
{ {
"Serilog": { "Serilog": {
"Using": [ "Serilog.Sinks.File" ], "Using": [ "Serilog.Sinks.File", "Serilog.Filters.Expressions" ],
"MinimumLevel": "Information", "MinimumLevel": "Information",
"WriteTo": [ "WriteTo": [
{ {
"Name": "File", "Name": "Logger",
"Args": { "Args": {
"path": "Logs/log_.log", "configureLogger": {
"rollingInterval": "Day", "Filter": [
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" {
"Name": "ByIncludingOnly",
"Args": {
"expression": "(@Level = 'Information')"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/actions_user_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
}
]
}
}
},
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "(@Level = 'Warning' or @Level = 'Error' or @Level = 'Fatal')"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/errors_.log",
"rollingInterval": "Day",
"outputTemplate": "{Message:lj} ({Timestamp:dd.MM.yyyy}){NewLine}{Exception}"
}
}
]
}
} }
} }
], ],