-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Description
Which version of Serilog.Sinks.Grafana.Loki are you using?
v8.2.0
Which version of .NET are you using?
net6.0
Describe the bug
Handling of Serilog.Events.LogEvent
in LokiBatchFormatter
is not thread-safe.
Method AddLevelAsPropertySafely
modifies Serilog.Events.LogEvent.Properties
(Dictionary<string, LogEventPropertyValue>
) and causes problems with simultaneous aceess to it from other threads (sinks).

serilog/serilog#1154 (comment)
Serilog's LogEvent is not thread-safe for readers concurrent with writers; concurrent reads are fine, but only in the absence of writes
To Reproduce
Configure at least one sink with async processing alongside Serilog.Sinks.Grafana.Loki, for example I use sinks:
- Serilog.Sinks.Async + Serilog.Sinks.File,
- Serilog.Sinks.Seq
Expected behavior
The original value of Serilog.Events.LogEvent.Properties
should never be modified in sink.
Log/SelfLog output or exception with stacktrace
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at Serilog.Formatting.Compact.CompactJsonFormatter.FormatEvent(LogEvent logEvent, TextWriter output, JsonValueFormatter valueFormatter)
at Serilog.Sinks.Seq.ConstrainedBufferedFormatter.Format(LogEvent logEvent, TextWriter output, Boolean writePlaceholders)
Application or code sample, which could be used to reproduce a bug
No response
Additional context
No response
I have read the documentation
- I have read Common Problems section in project wiki
mishamyte and oliver-unifii
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers