Using log4net declared as:
private readonly ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType());
In an async method or task, like this one:
public async void CheckSomething()
{
log.Info(null);
//....
}
logs MoveNext instead of CheckSomething.
Any idea how to make it log an actual method name?
All
asyncmethods are rewritten into a state machine to satisfy potentialawaitvalues within the method. The final method in which the code lives is theMoveNextmethod which is whatlog4netis reporting.There is really no good way at runtime to transition from
MoveNextto the actual method in which the code was originally written. They are somewhat disconnected at a metadata level. You may just have to resort to logging the name directly