-
Notifications
You must be signed in to change notification settings - Fork 153
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
Prevent allocation of Enumerator in CaptureMessageProperties #226
Prevent allocation of Enumerator in CaptureMessageProperties #226
Conversation
…ng to IReadOnlyList. ILogger extensions defined in Microsoft.Extensions.Logging.LoggerExtensions and LoggerMessage.Define() uses a state object that implements IReadOnlyList<KeyValuePair<string, object>>. By checking for this and using a for loop we can prevent allocation of an Enumerator.
Codecov Report
@@ Coverage Diff @@
## master #226 +/- ##
==========================================
- Coverage 72.15% 71.33% -0.82%
==========================================
Files 6 6
Lines 316 321 +5
Branches 75 78 +3
==========================================
+ Hits 228 229 +1
- Misses 59 63 +4
Partials 29 29
Continue to review full report at Codecov.
|
The code you are trying to optimize is only exercised when the initial parsing fails:
The initial parsing already attempts casting to |
Yes, but isn't that only executed if I enable CaptureMessageTemplate? If I don't want NLog to parse my message template, but still wants to log the state to event properties, I enable CaptureMessageProperties. |
CaptureMessageTemplate causes NLog to filter away the special event-property injected by Microsoft-Extension-Logging Any reason why you want this special event-property, and allocating a full Dictionary ? |
Thanks for taking the time to look into the PR. I'm closing it and will have a look at CaptureMessageTemplate. |
@agehrke I have reconsidered your proposal. And after seeing the effect of NLog parsing BeginScope, then I think it is a good idea to be able to skip all the parsing overhead. Have created #232 where |
Cool, thanks for letting me know. My use case is exactly what you mention in PR :) |
ILogger
extensions defined inMicrosoft.Extensions.Logging.LoggerExtensions
andLoggerMessage.Define()
uses a state object that implementsIReadOnlyList<KeyValuePair<string, object>>
. By checking for this and using a for loop we can prevent allocation of an Enumerator.