C#: Method Invocation Details
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();
}
}
精彩评论