-
Notifications
You must be signed in to change notification settings - Fork 104
Failed to write event through SerilogLogger: System.ArgumentException: An item with the same key has already been added. Key: EventId #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report 👍 |
… the template, the intrinsic event id wins; fixes serilog#273
A @aradalvand, the built-in |
@nblumhardt This is a pernicious departure from how the default Microsoft logger works; how about we introduce an opt-in configuration option to make this behavior consistent with the Microsoft logger? What I find more surprising is the fact that I couldn't seem to find any issues or docs talking about this. Could you point me to any? |
Also, why doesn't this apply to inline log statements then? This works, for example: logger.LogInformation("Foo {EventId}", eventId); |
No explicit event id is being specified, there.
There are a few similar points of divergence between the two. Serilog and this package both pre-date the default Microsoft logger, so the behavior chosen for this one was just what seemed best at the time. The Serilog.Extensions.Logging codebase was originally contributed by Microsoft, around the .NET Core 1.0 era, before there was a built-in logging implementation to compare it with :-)
This is what I mean by being open to other proposals 👍. It'd need concrete details in order to move forward (rough sketch of the design, analysis of possible breaking changes, alternatives considered, etc.). |
Yes working (Tested with configuration "Microsoft.XXX" filter set to "Trace" and Blazor Web Assembly 9.0.4). All mouse events containing eventid do not crash serilog anymore |
Thanks @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);
The text was updated successfully, but these errors were encountered: