我的 Global.asax.cs 中有这个 Application_Error 事件,它将获取我的应用程序中发生的任何未处理的异常。我能够收到错误消息。我还试图获取发生异常的类名和方法名,以便更容易追踪异常发生的位置和原因。请帮忙。
Global.asax.cs
protected void Application_Error(object sender, EventArgs e)
{
var errMsg = Server.GetLastError().Message;
if (string.IsNullOrWhiteSpace(errMsg)) return;
//Get Class name and method name
//ErrorLog.SaveLog(errMsg, Classname, Methodname);
Context.ClearError();
}
最佳答案
您可以使用 StackTrace 在调用堆栈中找到此信息,请参阅 http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe.aspx 中的示例.
关于c# - 从异常详情中获取异常发生的类名和方法名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15518528/