✅ serilog and appsettings.json unable to build configuration
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(
"../logs/webapi-Information-.log",
rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
.WriteTo.File(
"../logs/webapi-Error-.log",
rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error)
.CreateLogger();
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(
"../logs/webapi-Information-.log",
rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
.WriteTo.File(
"../logs/webapi-Error-.log",
rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error)
.CreateLogger();
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
"System": "Error"
}
},
"WriteTo:Information": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Information-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"WriteTo:Error": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Error-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
"System": "Error"
}
},
"WriteTo:Information": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Information-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"WriteTo:Error": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Error-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
WriteTo:Error:Name
has no Name element4 Replies
because it's an array
you need WriteTo:Error[0]:Name or something
"WriteTo" should contain a array of all your sink you want to write to:
you can add filters to specify which log-levels should go to which sink
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Information-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Error-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Information-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "File",
"Args": {
"path": "../logs/webapi-Error-.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
Right, you're not reading it yourself
Thanks a lot