Caller
-
현재 실행중인 함수 이름 가져오기dev/C# 2009. 9. 16. 15:56
에러 처리할 때 어느 함수에서 에러가 났는지 로그가 남으면 알기 편할 것 같아서 로거를 만들다가... 현재 실행중인 함수 이름 가져오기 using System.Reflection; void FunctionNameTest() { string currentFunction = MethodBase.GetCurrentMethod().Name; try { } catch (Exception ex) { Console.WriteLine("ERR at {0}.", currentFunction); } finally { } } 이런식으로 사용하면 된다. 더 자세한 함수 호출관계를 알려면 StackTrace, StackFrame, MethodBase 클래스들을 잘 섞어쓰면 된다. (관련예제 자세한 것 http://www.cod..