Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1011833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:51:11+00:00 2026-05-16T09:51:11+00:00

can Log method of class A get to know who calls it ? class

  • 0

can Log method of class A get to know who calls it ?

class A
{
    public void Log(string msg)
    {
        Log.Write("method_name: " + msg);
    }
}

I want to know a name of class and a name of a method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:51:12+00:00Added an answer on May 16, 2026 at 9:51 am

    You can use the StackTrace and StackFrame classes. You can either get a whole stack trace by calling the StrackTrace constructor, or just a particular stack frame using the StackFrame constructor which takes the number of frames to skip.

    You should be aware that it can be inaccurate due to inlining. (e..g method A inlines method B which calls your method – method A will be reported, not B).

    Sample code:

    using System;
    using System.Diagnostics;
    
    class Test
    {
        static void ShowCaller()
        {
            // Use this code if you want multiple frames
            // StackTrace trace = new StackTrace();
            // StackFrame frame = trace.GetFrame(1);
    
            // Use this code if you're only interested in one frame
            StackFrame frame = new StackFrame(1);
            Console.WriteLine(frame.GetMethod());
        }
    
        static void Intermediate()
        {
            ShowCaller();
        }
    
        static void Main()
        {
            Intermediate();
        }
    }
    

    Running as an optimized release build, this will print Void Main() – when running a debug build, or if you put more code into the Intermediate() method, it will print Void Intermediate().

    (As mentioned in comments, this will also create a performance hit. You should measure it to see if it’s acceptable in your particular case.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to know: How can I delete 'log.txt' if the last modification
I have an abstract Logger class with a virtual Log(std::string const&) method. That way
Is there a way I can set up callbacks on (or automataically log) method
When using log4j, the Logger.log(Priority p, Object message) method is available and can be
i want users can log in my website throw FB connect ON MOBILE but
How can I get the value of userId passed to this method in my
I have a class to encrypt the connectionString. public class SKM { private string
I know we can use MBean to get WebLogic's status. For example, use JDBCDataSourceRuntimeMBean
I have the following method of copying files: public static void nioCopy(File source, File
Can you point me to some tutorial or samples on how I can log

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.