Last Scope.State why is it ToString'd rather than added as a separate Payload
ksmithRenweb opened this issue · 5 comments
To me it's a bug, but there has to be a use case.
I've been fighting this for 3 days since I thought it was a bug in my code. Here is my use case.
var logger = provider.GetService<ILogger<...>>();
var disposable = logger.BeginScope(new Dictionary<string, object> {{"Operation ID", Activity.Current.RootId}});
...
logger.LogInformation("Just did something")
...
disiposable.Dispose();
What I am seeing when it gets to Application Insights (I've tracked it to the Log method in EventFlowLogger.) Is that the Scope has the type in it "System.Collections.Generic.Dictionary`2[System.String,System.Object]".
Since my first Scope only has 1 Key Value Pair in it. It's ignored. So I don't get a Operation ID with some Activity Root Id.
The only way it makes sense is if I am using it wrong and I should always have an extra KVP appended to the end of the Scope to avoid this...
@karolz-ms Tagging you since you updated it to take dictionaries. Vs. only ReadOnlyList's.
The summary i sent the Lead Architect in my group. Adding it cause i thought it was funny afterwards.
"adding extra properties like this failes
new Dictionary<string, object> {{"Operation ID", Activity.Current.RootId}}
but this would work
new Dictionary<string, object> {{"Operation ID", Activity.Current.RootId}, {"",null}}
forehead smack."
Interesting, thanks for submitting this issue @ksmithRenweb Good thinking with the {"", null}
workaround!
I guess we need more tests in this area (Logger + simple/nested scopes). Will look at this more early next week, OK?
@karolz-ms Thanks! I'll keep an eye out for next week.
Just published Microsoft.Logging 1.4.5 package on nuget.org. This should fix it. Feel free to re-open if you run into any problems!