I am reading the ASP.NET core docs about logging and i have the impression that there is no consensus on how logging should be done. because i am newbie i would love some comments from more experienced developers about if my thought is wrong and if so why. here is what i think :
in ASP.NET core programs the sequence of events start from a controller (in response to UI events) and that controller calls some method in another class which calls others ..etc then the response comes back, something like this:
controller1.action1 => class1.somemethod( ) => class2.somemethod( )
this chain from the action to the first method call to the second method call is a "sequence of events" that represent how the app responded and processed the action. off course there are other actions and methods in the program, for example like this: (notice that class2.somemethod( ) is common between the two sequence of events)
controller1.action2 => class3.somemethod( ) => class2.somemethod( )
and there will be a lot of overlap. now if i am debugging in visual studio and i had unexpected result from a UI action i can do debugging session. but if the app is already in production and the customer called and said "15 minutes back i did this in the web site and some error message appeared" i need some logs to help me. and those logs need to be:
1- timestamped (so that i can trace that particular controller action the customer is complaining about)
2- i should be able (for any sequence of events i choose) to trace the sequence of events from the controller all the way back to the controller again.
doing #1 is easy. doing #2 may be tricky if there is some traffic on the site as there will be too many events saying that controller1.action1 called class1.somemethod( ) at about the same time.
What solution (i think) will give us power logging is this : each time a sequence of events is started (i.e. a controller action is invoked) a new GUID is generated and included in a special field in the log info , that GUID is also passed to the next method in the sequence so it can associate itself with that particular "sequence" . an EventId is also included so that we now can filter events by both "sequences" and by methods.
however , this approach seem to be extreme as all methods in your program has to have this extra GUID parameter !
by reading the "logging" page of the .net framework i can't see any way i can trace a "sequence".
the question : does my thoughts make any sense ? what am i missing ?