locked
How to get the function/event name(windows application, windows mobile)? RRS feed

  • Question

  • Hi

    I am writing error Logs in catch block. I wan to trace the function or event name. How can I get that...?

    How to get the function/even name?



    private int SaveAndUploadData()
       {
              
    try
    {

    }

    Catch(Exception ex)
    {
    ExceptionClass.WriteLog("FunctionName",ex.ToString());

    }
    }

    how do i get the funcationName, I dont want to hardcode the name.
    Thursday, August 27, 2009 9:51 AM

Answers

  • You can use the stack trace instead. Here is a demo:

                try
                {
                    throw new Exception("Some error occured");
                }
                catch(Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                }


    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Wednesday, September 2, 2009 3:34 AM
    Monday, August 31, 2009 11:17 AM

All replies

  • Hi Abinash,

    As you are writing your own logic to get logs, you need to hard code it.

    Regards,
    Malleswar
    Thursday, August 27, 2009 10:00 AM
  • Thank you Malleswar,

    However, I think there will be some option to get the current block name.....



    Thursday, August 27, 2009 10:07 AM
  • Hi Abinash,


    Actually for desktop there is an property to retrieve the method name.

    System.Reflection.

    MethodBase.GetCurrentMethod().Name

    But its not available with CF.

    Regards,
    Malleswar


    Thursday, August 27, 2009 10:28 AM
  • You can log line# and fileName in logfile using __LINE, __FILE macros if your app is MFC app.


    -Siva.
    Friday, August 28, 2009 7:14 AM
  • You can use the stack trace instead. Here is a demo:

                try
                {
                    throw new Exception("Some error occured");
                }
                catch(Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                }


    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Wednesday, September 2, 2009 3:34 AM
    Monday, August 31, 2009 11:17 AM