开发者

C#: Method Invocation Details

开发者 https://www.devze.com 2023-01-27 08:57 出处:网络
I have a website developed using C#. I want to see the caller of a method i.e, which method/event handler calls my method.

I have a website developed using C#. I want to see the caller of a method i.e, which method/event handler calls my method.

Suppose there is a button click. I would like to see it as follows

btnClick  BusinessLayerClass.SaveDocs(int docID, string docType) DataAccessLayerClass.Update()

btnClick  BusinessLayerClass.SaveDocs(int docID, string docType) DataAccessLayerClass.Increase()

Is it possible to see such a stack information?开发者_StackOverflow中文版 Please advise..

Note: All projects are added as dlls. There is no services like WCF.


System.Environment.StackTrace can be used

private void button1_Click(object sender, EventArgs e)
    {
                StackTrace st = new StackTrace(true);
        StackFrame[] fram = st.GetFrames();

        foreach (StackFrame sf in fram)
        {
            sf.GetFileColumnNumber();
            sf.GetFileLineNumber();
            sf.GetFileName();
            sf.GetILOffset();
            sf.GetMethod();

        }
    }  
0

精彩评论

暂无评论...
验证码 换一张
取 消