What's new in Serilog 4.0.0?
If you're deploying to .NET Framework, note that Serilog's assembly version number has been unpinned from the long-running historical
2.0.0default, and now matches the package version precisely. If you encounter issues, ensure your build is generating valid assembly binding redirects.
Simple, robust, built-in batching support
Sinks that need batching functionality can now be easily written, without any additional package dependencies, by implementing IBatchedLogEventSink:
class MyBatchedSink: IBatchedLogEventSink
{
public Task EmitBatchAsync(IReadOnlyCollection<LogEvent> batch)
{
// Send a batch of log events...
}
}Batched sinks can be added using WriteTo.Sink(IBatchedLogEventSink, ...) - they're given first-class consideration just like regular un-batched sinks.
The built-in batching implementation is based on System.Threading.Channels and draws on the original Serilog.Sinks.PeriodicBatching package (now in maintenance-mode), to provide a full-featured, efficient, async-native batching implementation.
Experimental dotted name capturing
By setting an experimental AppContext switch, message templates can be used to capture dotted names, which are required when using some logging schemas.
AppContext.SetSwitch("Serilog.Parsing.MessageTemplateParser.AcceptDottedPropertyNames", true);
Log.Information("Running as {user.name}", Environment.UserName);
// Captures {"user.name": "nblumhardt"}While currently experimental and unsupported, this flag is intended to help the ecosystem evaluate and prepare for dotted name support in a future Serilog release.
Changes
- #2015 — breaking unpin assembly version (@nblumhardt)
- #2045 — breaking use case-insensitive matching for level overrides (@tillig)
- #2051 — breaking recognize
UtcTimestampas a built-in token in output templates (@MatthewHays) - #1979 — add tests for
ReusableStringWriter(@nblumhardt) - #2016 — update TFMs (@nblumhardt, @bartelink)
- #2018 — add
LogEvent.UnstableAssembleFromParts()(@nblumhardt) - #2044 — build updates for compatibility (@tillig)
- #2027 — improve trimming annotations, compatibility switch for compiler-generated type support (@agocke)
- #2055 — introduce
IBatchedLogEventSinkandWriteTo.Sink(IBatchedLogEventSink)(@nblumhardt) - #2060 — introduce
LoggerSinkConfiguration.CreateSink()and redesign.Wrap()(@nblumhardt, @bartelink) - #2063 — improve
MessageTemplateParserperformance, switch to allow.in captured property names (@nblumhardt) - #2064 — make message template alignment parsing match spec (@Insomniak47)
- #2065 — allow any character except
}in message template format specifiers (@Insomniak47)