My situation is as follows:
- I have a form
FormBase
- From this
FormBaseList
andFormBaseDetail
are inherited
now on my mainform I want to log some exceptions from then FirstChanceException event. I log the Exception.Message
and the full stacktrace
But in the stacktrace
I have a problem.
For example I create a form FormCustomerDetail
and its derived from FormBaseDetail
.
And an exception occurs in a protected or private method defined in FormBaseDetail
then the stacktrace will show FormBaseDetail
in stead of FormCustomerDetail
This is a problem for me, because now I cant know what actual form the exception happend on. There are about 50 forms derived from FormBaseDetail
So the question is, is there a way in the FirstChanceException
event to retrieve the classname of the actual form ? Or the Name ?
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
private void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{
StackTrace stackTraceObject = new StackTrace();
string stackTrace = stackTraceObject.ToString();
// I need to retrieve the actual form name or classname here...
LogError(
//ActualFormName + Environment.NewLine +
e.Exception.GetType().FullName + Environment.NewLine +
e.Exception.Message + Environment.NewLine +
stackTrace);
}
Example of a logentry:
System.FormatException
Cannot convert xx to type boolean...
...
at Test_app.FormBaseDetail.OpenTables()
at Test_app.FormBaseDetail.PrepareFormLoad()
...
What I would like to get
Exeption occured in FormCustomerDetail
System.FormatException
Cannot convert xx to type boolean...
...
at Test_app.FormBaseDetail.OpenTables()
at Test_app.FormBaseDetail.PrepareFormLoad()
...