Skip to content
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

Add LoggingGenerator #51064

Merged
merged 123 commits into from
Apr 16, 2021
Merged

Add LoggingGenerator #51064

merged 123 commits into from
Apr 16, 2021

Conversation

maryamariyan
Copy link
Member

@maryamariyan maryamariyan commented Apr 11, 2021

Fixes #36022

More Info: https://github.com/dotnet/designs/blob/main/accepted/2021/logging-generator.md


CI Health:

  • wasm console log (link):
Stack trace
browser: Console websocket connected.
Arguments: --run,WasmTestRunner.dll,Microsoft.Extensions.Logging.Generators.Tests.dll,-notrait,category=IgnoreForCI,-notrait,category=OuterLoop,-notrait,category=failing
MONO_WASM: Initializing mono runtime
MONO_WASM: ICU data archive(s) loaded, disabling invariant mode
mono_wasm_runtime_ready
Initializing.....
System.AggregateException: One or more errors occurred. (Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.)
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'Microsoft.CodeAnalysis, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Reflection.MonoMethodInfo.GetMethodInfo(IntPtr handle)
   at System.Reflection.RuntimeMethodInfo.GetPseudoCustomAttributesData()
   at System.Reflection.CustomAttribute.GetPseudoCustomAttributesData(ICustomAttributeProvider obj, Type attributeType)
   at System.Reflection.CustomAttribute.GetCustomAttributesDataBase(ICustomAttributeProvider obj, Type attributeType, Boolean inheritedOnly)
   at System.Reflection.CustomAttribute.GetCustomAttributesData(ICustomAttributeProvider obj, Boolean inherit)
   at System.Reflection.CustomAttributeData.GetCustomAttributes(MemberInfo target)
   at System.Reflection.RuntimeMethodInfo.GetCustomAttributesData()
   at System.Reflection.MemberInfo.get_CustomAttributes()
   at Xunit.Sdk.ReflectionMethodInfo.GetCustomAttributes(MethodInfo method, Type attributeType, AttributeUsageAttribute attributeUsage)
   at Xunit.Sdk.ReflectionMethodInfo.GetCustomAttributes(MethodInfo method, String assemblyQualifiedAttributeTypeName)
   at Xunit.Sdk.ReflectionMethodInfo.GetCustomAttributes(String assemblyQualifiedAttributeTypeName)
   at ReflectionAbstractionExtensions.GetCustomAttributes(IMethodInfo methodInfo, Type attributeType)
   at Xunit.Sdk.XunitTestFrameworkDiscoverer.FindTestsForMethod(ITestMethod testMethod, Boolean includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
   at Xunit.Sdk.XunitTestFrameworkDiscoverer.FindTestsForType(ITestClass testClass, Boolean includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
   at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitDiscoverer.FindWithoutThreads(Boolean includeSourceInformation, IMessageSink discoveryMessageSink, ITestFrameworkDiscoveryOptions discoveryOptions)
   at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
   at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
   at SimpleWasmTestRunner.Main(String[] args)
   --- End of inner exception stack trace ---
Discovering: Microsoft.Extensions.Logging.Generators.Tests.dll (method display = ClassAndMethod, method display options = None)
WASM EXIT 1

Workaround: Exclude gen test project when TargetsMono set to true

TODO:

Separate from this PR:

Next PR

Martin Taillefer and others added 30 commits November 17, 2020 13:51
The `ISyntaxReceiver` is a syntax model that is more IDE friendly than
the pull model that was previously implemented. This allows the IDE to
push data to the generator as it is processing it. This is important
because the IDE is constantly "abandoning" analysis as the customer
types in the IDE which invalidates state and they quickly want to move
to calculating the new state
- Use the logger factory and console logger in the sample
- Support overriding the event name via the logger message attribute
- Added ToString override
- Enable dumping generated code in the sample for easy debugging
- GetEnumerator is now implemented by calling the indexer to avoid
some redundant code.

- Logging methods without arguments now share a common log state
struct, which eliminates redundant code to JIT.
- Add error checking to ensure the first argument to a logging method
implements the ILogger interface.

- Can now specify logging methods with generic
ILogger<T> as logger.

- Add error checking to prevent generic logging method parameters.

- Add error checking to ensure logging methods are static and partial

- Can now specify logging methods which different access modifiers.

- Eliminate or reduce cascading errors in many cases.

- Ensure generated symbol names all start with __ so as not to conflict
with user-specified symbols
int index = 0;
while (index < s.Length)
{
if (s[index] == '\n' || s[index] == '\r' || s[index] == '"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use string.IndexOfAny?

Copy link
Member Author

@maryamariyan maryamariyan Apr 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I could try on another PR or post preview 4.

- Feedback on ConvertEndOfLineAndQuotationCharactersToEscapeForm
- Add comment in versions.props
- Nit code style feedback
- Dont keep method when starts with underscore
@maryamariyan
Copy link
Member Author

maryamariyan commented Apr 16, 2021

reviewers

can I get a sign off on this PR if your blocking feedback is addressed?

cc @eerhardt @tarekgh @ericstj @safern

I will have a follow up to reduce source generator support (not allow source generation for larger than 6 arguments, etc.) but that would not drastically change all the changes reviewed here.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is great work that will benefit our customers. Let's get this feature in.

@maryamariyan maryamariyan merged commit 95f06ff into dotnet:main Apr 16, 2021
@ericstj
Copy link
Member

ericstj commented Apr 16, 2021

Woo hoo! Glad to see this in.
Test failures are known: #51346 and #51372 (thank you @eerhardt for filing these)

@jkotas jkotas mentioned this pull request Apr 17, 2021
@GrabYourPitchforks
Copy link
Member

@maryamariyan I generated the fwlinks and have pointed all of them to this issue for now. Once you create proper docs pages for all the newly introduced analyzer rules, feel free to change the fwlinks yourself (you should have write permission), or ping me and I can assist with changing them. Thanks!

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.

Enhance user-facing API for strongly-typed ILogger messages