Reputation: 2801
I have Serilog setup and logging in my application, however the date is not being appended to filename. The log file gets created as Log-.log
instead of Log-20220302.log
. Relevant code is shown below. The nuget package Serilog.Sinks.File
has been installed. Any ideas why?
public override void Bind(ref IContainer container)
{
container.Register(
() => new LoggerFactory(
new ILoggerProvider[]
{
new SerilogLoggerProvider(
new LoggerConfiguration()
.ReadFrom.AppSettings()
.Enrich.FromLogContext()
.CreateLogger()),
new DebugLoggerProvider(),
}).AddSerilog(),
DependencyScope.Singleton);
container.Register(typeof(ILogger<>), typeof(Logger<>), DependencyScope.Singleton);
}
Web.config
<appSettings>
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="C:\logs\Log-.log" />
<add key="serilog:write-to:File.rollingInterval" value="Day" />
</appSettings>
Upvotes: 1
Views: 1818
Reputation: 546
Notice the double period in the file name. Example output apilog.20220114.log
// API appsettings.json
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithProcessId",
"WithThreadId"
],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "%PROGRAMDATA%\\MyLogs\\apilog..log",
"rollingInterval": "Day",
"rollOnFileSizeLimit": true,
"fileSizeLimitBytes": 4194304,
"retainedFileCountLimit": 6,
"shared": true
}
}
]
},
Upvotes: 2