Skip to content

Failed to write event through SerilogLogger: System.ArgumentException: An item with the same key has already been added. Key: EventId #273

Closed
@gplogix

Description

@gplogix

In file SerilogLogger, in the function LogEvent PrepareWrite<TState>(LogEventLevel level, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter), if the state is IEnumerable<KeyValuePair<string, object> already contains a property "EventId", the following exception is triggered :
Failed to write event through SerilogLogger: System.ArgumentException: An item with the same key has already been added. Key: EventId.

Solution :
Replace :
properties.Add("EventId", _eventIdPropertyCache.GetOrCreatePropertyValue(in eventId));
By :
properties["EventId"] = _eventIdPropertyCache.GetOrCreatePropertyValue(in eventId);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions