Reputation: 83
I am getting the files to create in the logs folder, however they are empty. All except backup, which has all logs. Also if I keep in the
"rollingInterval": "Day"
inside the sublogger file args it will not create the file, which then does not give me a datestamp on the files. Why?
If I am missing something to help with this puzzle, I would gladly add it.
My logger calls:
Logger.LogCritical("Crtical");
Logger.LogDebug("Debug");
Logger.LogInformation("Information");
Logger.LogError("Error");
Logger.LogTrace("Trace");
Logger.LogWarning("Warning");
NuGet References:
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Exceptions" Version="6.1.0" />
<PackageReference Include="Serilog.Expressions" Version="2.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.1.2" />
<PackageReference Include="Serilog.Formatting.Elasticsearch" Version="8.4.1" />
<PackageReference Include="Serilog.Settings.AppSettings" Version="2.2.2" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
Here is my serilog appsettings:
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async", "Serilog.Expressions" ],
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:g} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}"
}
},
{
"Name": "File",
"Args": {
"outputTemplate": "[{Timestamp:g} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}",
"path": "logs\\Backup.log",
"rollingInterval": "Day",
"retainedFileCountLimit": "7",
"formatter": "Serilog.Formatting.Json.JsonFormatter"
}
},
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "@Level = 'Error'"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"outputTemplate": "[{Timestamp:g} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}",
"path": "logs\\error.log",
"formatter": "Serilog.Formatting.Json.JsonFormatter"
}
}
]
}
}
},
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "@Level = 'Information' or @Level = 'Debug' or @Level = 'Warning' or @Level = 'Fatal'"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"outputTemplate": "[{Timestamp:g} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}",
"path": "logs\\standard.log",
"rollingInterval": "Day",
"retainedFileCountLimit": "7",
"formatter": "Serilog.Formatting.Json.JsonFormatter",
"restrictedToMinimumLevel": "Information"
}
}
]
}
}
}
],
"Enrich": [ "FromLogContext", "WithExceptionDetails", "WithThreadId" ],
"Properties": {
"Application": "Application"
}
}
my output in backup.log:
[04/26/2021 14:20 FTL] [xxSoureContextxx] Crtical
[04/26/2021 14:20 INF] [xxSoureContextxx] Information
[04/26/2021 14:20 ERR] [xxSoureContextxx] Error
[04/26/2021 14:20 WRN] [xxSoureContextxx] Warning
Upvotes: 2
Views: 1972
Reputation: 83
Serilog.Filter.Expressions is deprecated but its syntax is @Level. As Nicholas pointed out in a comment above, Serilog.Expressions uses a syntax of @l. Everything worked including getting a file while using the interval.
Thanks Nicholas.
Upvotes: 4