benaadams / Ben.Demystifier

High performance understanding for stack traces (Make error logs more productive)
Apache License 2.0
2.74k stars 118 forks source link

Demystifier shows async methods in AOP aspect #218

Open deastr opened 9 months ago

deastr commented 9 months ago

I have a sample async console app with Aspect Oriented Programming logger, in this structure:

ConsoleApp
Project.Class.Method1
Project.Class.Method2

Call list is: ConsoleApp.Main -> Project.Class.Method1 -> Project.Class.Method2

All three of them are async.

This is the GetFrame list when observed by AOP logger while entering to Method2:

EnhancedStackTrace.Current().FrameCount
8
EnhancedStackTrace.Current().GetFrame(0).GetMethod().Name
"Method2"
EnhancedStackTrace.Current().GetFrame(1).GetMethod().Name
"MoveNext"
EnhancedStackTrace.Current().GetFrame(2).GetMethod().Name
"Start"
EnhancedStackTrace.Current().GetFrame(3).GetMethod().Name
"Method1"
EnhancedStackTrace.Current().GetFrame(4).GetMethod().Name
"MoveNext"
EnhancedStackTrace.Current().GetFrame(5).GetMethod().Name
"Start"
EnhancedStackTrace.Current().GetFrame(6).GetMethod().Name
"Main"
EnhancedStackTrace.Current().GetFrame(7).GetMethod().Name
"<Main>"

Interestingly .ToString() method shows somewhat different list:

 at Task Project2.Class1.Method2()
 at async Task Project2.Class1.Method1()
 at void System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine)
 at Task Project2.Class1.Method1()
 at async Task Application.Program.Main(string[] args)
 at void System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine)
 at Task Application.Program.Main(string[] args)
 at void Application.Program.<Main>(?)

I'm attaching sample project.

test.zip