KeyValuePairSettings - support Serilog.Sinks.Async and other simple wrappers
See original GitHub issuePlease describe the current behavior?
Serilog.Sinks.Async is proving to be a popular way to reduce the latency of non-batched sinks, such as the console and file.
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(
a => a.File("logs/myapp.txt", rollingInterval: RollingInterval.Day),
bufferSize: 1000)
.CreateLogger()
There’s currently no support for applying the wrapper in XML/key-value settings.
Please describe the expected behavior?
Based on @emrahcetiner’s suggestion in the linked issue; the equivalent of the above would be:
<add key="serilog:using:Async" value="Serilog.Sinks.Async" />
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<!-- This is a regular, direct parameter on `WriteTo.Async()` -->
<add key="serilog:write-to:Async.bufferSize" value="1000" />
<!-- `configure` is an `Action<LoggerSinkConfiguration>`; since `LoggerSinkConfiguration`
is the basis of the `write-to` syntax, we behave as if the directive to the left
of `File` is effectively a `write-to` -->
<add key="serilog:write-to:Async.configure:File.path" value="logs/myapp.txt" />
<add key="serilog:write-to:Async.configure:File.rollingInterval" value="Day" />
This is quite similar to how nested actions are handled in Serilog.Settings.Configuration.
The simple syntax doesn’t work for all lambda arguments, i.e. ones with more than a single parameter of a *Configuration type like Serilog.Sinks.Map, but, it could provide a basis for WriteTo.Logger() support:
<add key="serilog:write-to:Logger.configureLogger:write-to:File.path" value="logs.txt" />
<add key="serilog:write-to:Logger.configureLogger:filter:ByIncludingOnly.expression"
value="@Level = 'Warning'" />
(I’d seriously consider taking a source-breaking change to rename that configureLogger parameter to just configure…)
Ideally, the syntax should be regular and predictable enough for Serilog Analyzer to work with (cc @Suchiman).
Thoughts?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Related StackOverflow Question
Looks good !
The syntax takes a bit to parse for a human being, but it’s at least is is “Making Simple Things Simple, Making Complex Things Possible” 😃
So if I understand correctly, based on your examples, this means supporting parameters of type :
Action<LoggerSinkConfiguration>, akawrite-toAction<LoggerConfiguration>… and then allow sub-settingswrite-to,audit-to,filteretcI don’t know if it’s worth implementing also
Action<LoggerAuditSinkConfiguration>(audit-to),Action<LoggerEnrichmentConfiguration>(enrich) andAction<LoggerFilterConfiguration>(filter) … but it might be harder to “not implement them” :p@0x15e Just wanted to let you know that there is a port of Serilog.Settings.Configuration to XML with much less dependencies 😉 https://github.com/serilog-contrib/serilog-settings-xml2
Remarks: I’m the author