Skip to content

Extensions.Logging: JsonConsoleFormatter serializes scope and state properties using native json type - #40067

Merged
maryamariyan merged 6 commits into
dotnet:masterfrom
alefranz:jsonconsoleformatter-primitivetypes
Aug 11, 2020
Merged

maryamariyan merged 6 commits into
dotnet:masterfrom
alefranz:jsonconsoleformatter-primitivetypes

Conversation

@alefranz

Copy link
Copy Markdown
Contributor

This PR changes the JsonConsoleFormatter to convert the values of the k/v in state and scope to json native types when it is a built-in value type.

I haven't found a way to remove converters easily from the JsonSerializer.
I used the JsonSerializer as I didn't want to reimplement the logic.

Should I reimplement the serialization logic to avoid the cost of the JsonSerializer? Is there already something available I can reuse?
Should I add support for NullableTypes?

Fixes #39870

/cc @maryamariyan

@ghost

ghost commented Jul 29, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

@alefranz
alefranz force-pushed the jsonconsoleformatter-primitivetypes branch from 3a0b737 to 5587060 Compare July 31, 2020 07:51
@alefranz
alefranz force-pushed the jsonconsoleformatter-primitivetypes branch from 5587060 to 63abb17 Compare July 31, 2020 08:06
@alefranz
alefranz force-pushed the jsonconsoleformatter-primitivetypes branch from 307be3d to 0a5209a Compare July 31, 2020 17:09
@alefranz

Copy link
Copy Markdown
Contributor Author

I've addressed the feedback and refactored the tests to add coverage for nullables.

@alefranz

alefranz commented Aug 1, 2020

Copy link
Copy Markdown
Contributor Author

Test failures seems unrelated

@alefranz
alefranz force-pushed the jsonconsoleformatter-primitivetypes branch from 458931c to 1297fe0 Compare August 5, 2020 07:18
@alefranz

alefranz commented Aug 5, 2020

Copy link
Copy Markdown
Contributor Author

Feedback should be addressed now and I've rebased it

@maryamariyan

maryamariyan commented Aug 5, 2020 •

Copy link
Copy Markdown
Contributor

There are some Logging.Console.Tests failures to look at here: https://dev.azure.com/dnceng/public/_build/results?buildId=757755&view=ms.vss-test-web.build-test-results-tab&runId=23523088&resultId=101163&paneView=debug

e.g. for: Microsoft.Extensions.Logging.Console.Test.JsonConsoleFormatterTests.Log_StateAndScopeContainsFloatingPointType_SerializesValue(value: 1,2)

Error Message:

Assert.Equal() Failure\r\nExpected: 1,2 (rounded from 1,2)\r\nActual:   12 (rounded from 12)

StackTrace:

at Microsoft.Extensions.Logging.Console.Test.JsonConsoleFormatterTests.<Log_StateAndScopeContainsFloatingPointType_SerializesValue>g__AssertMessageValue|7_0(String message, String propertyName) in /_/src/libraries/Microsoft.Extensions.Logging.Console/tests/JsonConsoleFormatterTests.cs:line 306
   at Microsoft.Extensions.Logging.Console.Test.JsonConsoleFormatterTests.Log_StateAndScopeContainsFloatingPointType_SerializesValue(Object value) in /_/src/libraries/Microsoft.Extensions.Logging.Console/tests/JsonConsoleFormatterTests.cs:line 297
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /_/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs:line 384

@alefranz
alefranz force-pushed the jsonconsoleformatter-primitivetypes branch from 1297fe0 to 6bf9992 Compare August 6, 2020 07:15
@maryamariyan

Copy link
Copy Markdown
Contributor

It's looking good to me. You'll need to resolve the conflict now.

@alefranz
alefranz force-pushed the jsonconsoleformatter-primitivetypes branch from c585684 to b476d61 Compare August 8, 2020 10:28
@alefranz

alefranz commented Aug 8, 2020

Copy link
Copy Markdown
Contributor Author

I've rebased it but there are some unrelated tests failing in CI

@maryamariyan
maryamariyan merged commit bfe783c into dotnet:master Aug 11, 2020
@maryamariyan

Copy link
Copy Markdown
Contributor

Failure is #40627

@alefranz

Copy link
Copy Markdown
Contributor Author

Thank you for the help!

@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonConsoleFormatter: number and boolean properties should not be converted to string

5 participants