普通方法(非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}");
}