Results 1 to 4 of 4

Thread: Name of Calling function [Resolved]

  1. #1

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Name of Calling function [Resolved]

    Hi,
    I have Classes that are shared between web apps and windows apps. One of my class is an Error Hanlder which handles all errors and logs them. Now if the class is used in Windows App i display the error message using message box, now since in ASP.Net i cant display Message Box, i want to display the error message using Trace class.

    Now what i need a way of identifying whether the class is used in ASP.net or C#. So i can do something like

    if (Source) = WinApp
    {
    MessageBox(ex.Message);

    LogError(ex);
    }
    else
    {
    WriteTraceInfo(ex);
    LogError(ex);
    }

    Thanks for any help.
    Last edited by Danial; Aug 3rd, 2004 at 04:17 AM.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Why not pass that info into the constructor of your error handler? The author of the calling application knows what type of app it is (or at least you would hope).
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Code:
    // Code to get the method name...
    string methodName = GetCallingMethod().Name;
    
    private System.Reflection.MethodBase GetCallingMethod()
    {
    	// Get the current stack frame, and skip the first two frames.
    	System.Diagnostics.StackFrame frame =
    		new System.Diagnostics.StackFrame(2, false);
    	// Return the first method in the stack frame, as this will be the
    	// calling function.
    	return frame.GetMethod();
    }

  4. #4

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Thank you, axion_sa and Blade..

    I happily consider this tread resolved
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width