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

[AOT] Refactor Logger function and mark managedCommon as AOT compatible #36327

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

moooyo
Copy link
Contributor

@moooyo moooyo commented Dec 13, 2024

Summary of the Pull Request

  • clean up some AOT build issue
  • Refactor Log function. Use System.AppContext to get the application path.
  • Log CallerMemberName, File, LineNumber in logger and remove GetCallerInfo.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@moooyo moooyo added the Needs-Review This Pull Request awaits the review of a maintainer. label Dec 13, 2024
@moooyo
Copy link
Contributor Author

moooyo commented Dec 13, 2024

When we publish application with AOT enable. Some reflection usage will be forbidden. So, we need to make this change.

@moooyo
Copy link
Contributor Author

moooyo commented Dec 13, 2024

old log format: [05:29:23.8888162] [Info] Program::Main
new log format: [14:46:19.3222642] [Info] TrayHelper.cs::RunOnMainThread::356

@crutkas crutkas added In for .88 Don't merge - Hold for release Hold off on merging this PR, even if it's approved. labels Dec 13, 2024
Copy link

@yeelam-gordon yeelam-gordon left a comment

Choose a reason for hiding this comment

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

I believe we need advice + know the knowledge on how to analysis PowerToys logging :-D

throw;
#endif
}
string fileName = Path.GetFileName(sourceFilePath);

Choose a reason for hiding this comment

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

May be Path.GetFileNameWithoutExtension?
Looks like this will throw exception as well, although I don't see why. Just to be safe in case.

Choose a reason for hiding this comment

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

I believe with this way, the original strange code for "async method" should be not only gone, but much more reliable, we can put as part of benefit for this change after testing.

}

private static MethodBase GetCallerMethod(StackTrace stackTrace)
private static string GetCallerInfo(string memberName, string sourceFilePath, int sourceLineNumber)

Choose a reason for hiding this comment

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

For sourceLineNumber.
Given originally they don't have, we need to ask for PMs, that any parser of the log it will break this.
If Yes, we should still keep the original "TypeName::MethodName" format first.

Last but not least, do we know how to view PowerToys log? If we can parrse the log and show a summary of before after, it will give confidence of this changes.

{
Log(string.Empty, TraceFlag);
Log(string.Empty, TraceFlag, memberName, sourceFilePath, sourceLineNumber);
}

[MethodImpl(MethodImplOptions.NoInlining)]

Choose a reason for hiding this comment

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

May be we don't need this one anymore.

@@ -53,18 +52,37 @@ public static void InitializeLogger(string applicationLogPath, bool isLocalLow =
Trace.AutoFlush = true;
}

public static string GetVersion()

Choose a reason for hiding this comment

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

Can we just ask the caller to pass in its own class type?
From Github copilot, the following code should be AOT compatible:
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(Program).Assembly.Location);
Console.WriteLine($"Version: {versionInfo.FileVersion}

@jaimecbernardo jaimecbernardo removed the Don't merge - Hold for release Hold off on merging this PR, even if it's approved. label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In for .88 Needs-Review This Pull Request awaits the review of a maintainer.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants