I am logging log using log4net in an ActionMethod whose name is LogHandlerMethod(). That ActionMethod is called inside different functions(Actions). How to get methodname of those functions inside which LogHandlerMethod() has been called
Asked
Active
Viewed 192 times
1 Answers
0
You can do this with a CallerMemberNameAttribute:
public void LogHandlerMethod(... my parameters ... ,[CallerMemberName]string memberName = "")
{
//memberName will contain name of calling method
Call this without the adding the memberName parameter (the memberName will be filled by the CallerMemberNameAtribute)

Peter
- 27,590
- 8
- 64
- 84
-
Do I need to pass in function as argument. What if I want to access in code? – Sachit Murarka Feb 17 '17 at 11:22
-
The CallerMemberNameAttribute takes care of setting the name of the caller function. Do not pass the memberName as parameter in your caller function. – Peter Feb 17 '17 at 11:35
-
I have to make comparison in webconfig files. Say if this method has been been from particular action do something otherwise do something else. – Sachit Murarka Feb 20 '17 at 09:13