0
点赞
收藏
分享

微信扫一扫

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


普通方法(非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 条评论