Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void WriteScopeInformation(Utf8JsonWriter writer, IExternalScopeProvider
writer.WriteStartArray("Scopes");
scopeProvider.ForEachScope((scope, state) =>
{
if (scope is IReadOnlyCollection<KeyValuePair<string, object>> scopes)
if (scope is IEnumerable<KeyValuePair<string, object>> scopes)
{
state.WriteStartObject();
state.WriteString("Message", scope.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,35 @@ public void Log_StateAndScopeContainsNullValue_SerializesNull()
Assert.Contains("\"LogKey\":null", message);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void Log_ScopeIsIEnumerable_SerializesKeyValuePair()
{
// Arrange
var t = SetUp(
new ConsoleLoggerOptions { FormatterName = ConsoleFormatterNames.Json },
simpleOptions: null,
systemdOptions: null,
jsonOptions: new JsonConsoleFormatterOptions
{
JsonWriterOptions = new JsonWriterOptions() { Indented = false },
IncludeScopes = true
}
);
var logger = (ILogger)t.Logger;
var sink = t.Sink;

// Act
using (logger.BeginScope(new[] { 2 }.Select(x => new KeyValuePair<string, object>("Value", x))))
{
logger.LogInformation("{LogEntryNumber}", 1);
}

// Assert
string message = sink.Writes[0].Message;
Assert.Contains("\"Message\":\"System.Linq.Enumerable", message);
Assert.Contains("\"Value\":" + 2, message);
}

public static TheoryData<object, string> SpecialCaseValues
{
get
Expand Down