Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Getting event/method name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vikram - 19 Jul 2007 09:30 GMT
is there any object available in c#/asp.net which can give me event name in
that eevnt only. Like if I am in Page_load event, i should get Page_Load or
if I am in Button_click event I should get Button_Click. SO that I can logg
it in my cutom log file with a generic logic.

Thanks
Eliyahu Goldin - 19 Jul 2007 09:51 GMT
Look at the TraceEventCache.Callstack property and the StackTrace class.
From the MSDN:

The Callstack property gets the call stack from the StackTrace property of
the Environment class. The property value lists method calls in reverse
chronological order. That is, the most recent method call is described
first. One line of stack trace information is listed for each method call on
the stack. For more information, see StackTrace.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> is there any object available in c#/asp.net which can give me event name
> in
[quoted text clipped - 5 lines]
>
> Thanks
Manish Bafna - 19 Jul 2007 10:40 GMT
Hi,
If you're writing a tracing and logging component you may well want to pass
the current method name to your logging component. Rather than hard code it
(then forget to change it when you change the method name) you can use
reflection and the MethodBase class to retrieve the name.

System.Reflection.MethodBase currentMethod =
System.Reflection.MethodBase.GetCurrentMethod();
System.Diagnostics.Debug.WriteLine(currentMethod.Name);
System.Diagnostics.Debug.WriteLine(currentMethod.DeclaringType.Name);
System.Diagnostics.Debug.WriteLine(currentMethod.DeclaringType.Namespace);

ref:http://idunno.org/archive/2004/12/03/163.aspx
Signature

Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> is there any object available in c#/asp.net which can give me event name in
> that eevnt only. Like if I am in Page_load event, i should get Page_Load or
> if I am in Button_click event I should get Button_Click. SO that I can logg
> it in my cutom log file with a generic logic.
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.