C#中获取当前namespace和methodName(static上下文中也可用)

阅读 23

2022-09-06


普通方法(非static方法,也非在static class中的方法)获取namespace和methodName就很简单了,反射。略过。


现在是在static方法中获取namesapce和methodName的写法:


try
{

}
catch (Exception e)
{
var curNamespace = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType;
var curMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
LogHelper.WriteError($"{curNamespace}.{curMethodName}\n {e.Message} \t {e.TargetSite}");
}



精彩评论(0)

0 0 举报