-
Notifications
You must be signed in to change notification settings - Fork 795
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
Optimize AddPropertyIfAbsent #1872
Changes from 2 commits
359cba0
481cbb5
de91056
ff82a3b
79daf64
3ae6570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2013-2015 Serilog Contributors | ||
// Copyright 2013-2015 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -107,6 +107,8 @@ public string RenderMessage(IFormatProvider? formatProvider = null) | |
/// </summary> | ||
public IReadOnlyDictionary<string, LogEventPropertyValue> Properties => _properties; | ||
|
||
internal Dictionary<string, LogEventPropertyValue> PropertiesDictionary => _properties; | ||
|
||
/// <summary> | ||
/// An exception associated with the event, or null. | ||
/// </summary> | ||
|
@@ -192,3 +194,18 @@ internal LogEvent Copy() | |
properties); | ||
} | ||
} | ||
|
||
internal static class LogEventExtensions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nblumhardt For now it's
|
||
{ | ||
public static void AddPropertyIfAbsent(this LogEvent evt, ILogEventPropertyFactory factory, string name, object? value, bool destructureObjects = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we already end up adding an I can see how dependent libraries would benefit from making this accessible, but in that case we'd have to expose something on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
if (!evt.Properties.ContainsKey(name)) | ||
{ | ||
evt.PropertiesDictionary.Add( | ||
name, | ||
factory is ILogEventPropertyValueFactory factory2 | ||
? factory2.CreatePropertyValue(value, destructureObjects) | ||
: factory.CreateProperty(name, value, destructureObjects).Value); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this interface was just missed.