我正在获取要在logs文件夹中创建的文件,但是它们是空的。除了备份,它有所有的日志。另外,如果我一直在
"rollingInterval": "Day"
在sublogger文件args中,它不会创建该文件,因此不会给我文件上的日期戳。为什么?
如果我遗漏了一些东西来帮助解决这个难题,我会很乐意补充它。
我的记录器调用:
Logger.LogCritical("Crtical");
Logger.LogDebug("Debug");
Logger.LogInformation("Information");
Logger.LogError("Error");
Logger.LogTrace("Trace");
Logger.LogWarning("Warning");
NuGet参考:
<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" />
下面是我的serilog应用程序设置:
"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"
}
}
我在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
发布于 2021-04-27 22:55:15
Serilog.Filter.Expressions已弃用,但其语法为@Level。正如Nicholas在上面的评论中指出的那样,Serilog.Expressions使用了@l的语法。所有的工作都在进行,包括在使用interval时获得一个文件。
谢谢尼古拉斯。
https://stackoverflow.com/questions/67272869
复制相似问题