1.被简化之前
对已LogHelper,形如:
public static void WriteError(string className,string methodName,string message){ //...}public static void WriteDebug(string className, string methodName, string message){ //...}
大家都知道要干嘛,调用时这样的:
LogHelper.WriteDebug("BusFlowBase", "DoWork", string.Format("公司在平台查询订单查询完毕。"));
2.简化之后
public static void WriteError(string message){ var sf = new StackFrame(1); //1表示离栈顶还差一个。 var callMethod = sf.GetMethod(); WriteError(callMethod.DeclaringType.Name, callMethod.Name, message);}public static void WriteError(string className, string methodName, string message){ //...}public static void WriteDebug(string message){ var sf = new StackFrame(1); var callMethod = sf.GetMethod(); WriteDebug(callMethod.DeclaringType.Name, callMethod.Name, message);}public static void WriteDebug(string className, string methodName, string message){ //...}
调用时这样的:
LogHelper.WriteDebug( string.Format("公司在平台查询订单查询完毕。"));
舒服吧?!!!