You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Logging Source Generator, the generated code looks like:
// <auto-generated/>
#nullable enable
namespaceClassLibrary1{partialclassClass1{[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators","6.0.0.0")]privatereadonlystruct__HealthCheckErrorStruct:global::System.Collections.Generic.IReadOnlyList<global::System.Collections.Generic.KeyValuePair<string,object?>>{privatereadonlyglobal::System.String_HealthCheckName;privatereadonlyglobal::System.Double_ElapsedMilliseconds;public__HealthCheckErrorStruct(global::System.StringHealthCheckName,global::System.DoubleElapsedMilliseconds){this._HealthCheckName=HealthCheckName;this._ElapsedMilliseconds=ElapsedMilliseconds;}publicoverridestringToString(){varHealthCheckName=this._HealthCheckName;varElapsedMilliseconds=this._ElapsedMilliseconds;return$"Health check {HealthCheckName} threw an unhandled exception after {ElapsedMilliseconds}ms";}publicstaticstringFormat(__HealthCheckErrorStructstate,global::System.Exception?ex)=>state.ToString();publicintCount=>3;publicglobal::System.Collections.Generic.KeyValuePair<string,object?>this[intindex]{get=>indexswitch{0=>newglobal::System.Collections.Generic.KeyValuePair<string,object?>("HealthCheckName",this._HealthCheckName),1=>newglobal::System.Collections.Generic.KeyValuePair<string,object?>("ElapsedMilliseconds",this._ElapsedMilliseconds),2=>newglobal::System.Collections.Generic.KeyValuePair<string,object?>("{OriginalFormat}","Health check {HealthCheckName} threw an unhandled exception after {ElapsedMilliseconds}ms"),
_ =>thrownewglobal::System.IndexOutOfRangeException(nameof(index)),// return the same exception LoggerMessage.Define returns in this case};}
Notice a few differences:
Logging Source Generator has // <auto-generated/> and #nullable enable at the top of the file. Json doesn't.
Logging Source Generator uses GeneratedCodeAttribute on the generated code.
Logging Source Generator uses global::fully.qualified.name and no usings. Json source generator looks more like code a "normal dev" would write.
We should be consistent between these source generators in what the generated code looks like. That way we don't have bugs/bad user experiences with one generator that don't apply to the other.
Logging Source Generator has // and #nullable enable at the top of the file. Json doesn't.
Logging Source Generator uses GeneratedCodeAttribute on the generated code.
Logging Source Generator uses global::fully.qualified.name and no usings. Json source generator looks more like code a "normal dev" would write.
The PR #53212 has addressed all of these, except having #nullable enable at the top of each file.
When you use the System.Text.Json source generator, the generated code looks like:
When using the Logging Source Generator, the generated code looks like:
Notice a few differences:
// <auto-generated/>
and#nullable enable
at the top of the file. Json doesn't.GeneratedCodeAttribute
on the generated code.global::fully.qualified.name
and nousings
. Json source generator looks more like code a "normal dev" would write.We should be consistent between these source generators in what the generated code looks like. That way we don't have bugs/bad user experiences with one generator that don't apply to the other.
cc @layomia @maryamariyan
The text was updated successfully, but these errors were encountered: