KeyValuePairSettings - support Serilog.Sinks.Async and other simple wrappers

See original GitHub issue

Please 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:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tsimbalarcommented, Dec 21, 2017

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> , aka write-to
  • Action<LoggerConfiguration> … and then allow sub-settings write-to , audit-to, filter etc

I don’t know if it’s worth implementing also Action<LoggerAuditSinkConfiguration> (audit-to), Action<LoggerEnrichmentConfiguration> (enrich) and Action<LoggerFilterConfiguration> (filter) … but it might be harder to “not implement them” :p

1reaction
Khaos66commented, Dec 1, 2021

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does Serilog.Sinks.Console sink get any benefits from ...
1 Answer 1 ... The Async Sink takes the already-captured LogEvent items and shifts them to a single background processor from multiple foreground ......
Read more >
Serilog.Sinks.Async 1.5.0
Asynchronous sink wrapper for Serilog.
Read more >
Serilog Tutorial - Structured Blog - Datalust
Async wrapper - the latency of logging to files or the console can be reduced further using the Serilog.Sinks.Async package; Sink READMEs -...
Read more >
Serilog — simple .NET logging with fully-structured events
NET, Serilog provides diagnostic logging to files, the console, and elsewhere. It is easy to set up, has a clean API, and is...
Read more >
What's new in Serilog? (October 2016)
Async provides WriteTo.Async() . This wrapper moves logging onto a worker thread, so that application code can continue executing while file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found