// Test log protected void writeerror (Object sender, eventargs e) {string typename = This. getType (). tostring (); // when the class name is used // string methodname = new system. diagnostics. stacktrace (true ). getframe (1 ). getmethod (). declaringtype. tostring (); // This can be printed by the button call // string methodname = new system. diagnostics. stacktrace (true ). getframe (1 ). getmethod (). name; // event source, onclick, but the writeerror method name is not displayed .. String methodname = system. reflection. methodbase. getcurrentmethod (). Name ;//ProgramExecution locationCodeBlock Method Name // response. write (typename + "," + methodname + "," + method + ","); string errmsg = "test err message"; log. write (enums. logtype. error, errmsg, "type name:" + typename, "method name:" + methodname );}
Directly run the code, that is, the current GetType () can be used for the current class name. In addition, the system. Diagnostics. stacktrace and system. reflection. methodbase functions greatlyArticleYou can dig. Go to msdn.
The current page is test. aspx. CS.
The output of the above three methodnames is as follows. Use them by yourself.
2010-09-29 16:30:23 test err message
Type name: Asp. test_aspx)
Method Name: system. Web. UI. webcontrols. Button
2010-09-29 16:30:52 test err message
Type name: Asp. test_aspx
Method Name: onclick
2010-09-29 16:31:11 test err message
Type name: Asp. test_aspx
Method Name: writeerror (Exactly What I Want)