ssg31415926 schreef:
> I want to write a logging method. I want it to log the name of the
> calling class and method. Is there any way to do this? I presume
> it'll use Reflection but it's not an area I've used much.a
>
> Alternatively, is there a piece of code I can use to pass in the name
> of the method, so that I can copy and paste the calling code and don't
> have to remember to change a hard coded method name.
>
> I could code this:
>
> Log("callingClass.CallingMethod", someData, someLogCode);
>
> but I'd rather code this:
>
> Log(someData, someLogCode); and have it work out what the calling
> method was.
>
> or at least, this:
>
> Log(System.Reflection.Blah.CurrentMethod, someData, someLogCode);
Log(MethodBase.GetCurrentMethod().DeclaringType,MethodBase.GetCurrentMethod().Name);
--
Tim Van Wassenhove <url:http://www.timvw.be/>
|