MoveNext 而不是实际的方法/任务名称 [英] MoveNext instead of actual method/task name

查看:26
本文介绍了MoveNext 而不是实际的方法/任务名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 log4net 声明为:

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);
    //....
}

记录 MoveNext 而不是 CheckSomething.知道如何让它记录一个实际的方法名称吗?

logs MoveNext instead of CheckSomething. Any idea how to make it log an actual method name?

推荐答案

所有 async 方法都被重写到状态机中,以满足方法中潜在的 await 值.代码所在的最后一个方法是 MoveNext 方法,它是 log4net 报告的方法.

All async methods are rewritten into a state machine to satisfy potential await values within the method. The final method in which the code lives is the MoveNext method which is what log4net is reporting.

在运行时确实没有好的方法可以从 MoveNext 转换到最初编写代码的实际方法.它们在元数据级别上有些脱节.您可能只需要直接记录名称

There is really no good way at runtime to transition from MoveNext to 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

这篇关于MoveNext 而不是实际的方法/任务名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆