I need to find a way to get the class file name that an exception will be thrown in. for example the project's tree structure would be
SchoolCourses (assembly name)
->GraduatePrograms.cs
->UndergraduatePrograms.cs
->CommunityPrograms.cs
->SchoolCourseMain.cs
I have tried System.Reflection:
return "ERROR:\n An error has occurred in " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
output:
ERROR:
An error has occurred in SchoolCourses
However, that is returning the project name, I would like it to be more along the lines of
output:
ERROR:
An error has occurred in SchoolCourses.GraduatePrograms
您可以只使用this.GetType().Name
return "ERROR:\n An error has occurred in " + this.GetType().Name;
An alternative might be to use Environment.StackTrace
property.
http://msdn.microsoft.com/en-us/library/system.environment.stacktrace%28v=vs.110%29.aspx
The StackTrace property formats the stack trace information for each method call as follows:
"at FullClassName.MethodName(MethodParams) in FileName :line LineNumber "
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.