How to get the values ​​of variables in a stack trace dump?

I support an application that sends me an email when an error occurs in the application. I drop the stack trace to email and it seems to work fine. The only thing missing is the value of the variables. I get all the calls, etc., just no variables. What am I missing to get these values ​​of variables dumped to email?

Below is the code that I use to send it in an email:

UtilityClass.SendEmail(shortNTID,
                       "admin@mydomain.com",
                       new string[] { "support@mydomain.com" },
                       "MyApplication error has occured for user: " +
                            shortNTID + " (Main).",
                       "Message: " + ex.Message.ToString() +
                       " Source: " + ex.Source.ToString() +
                       " Target Site: " + ex.TargetSite.ToString() +
                       " Stack Trace: " + ex.StackTrace.ToString());

And here is the result in the email:

Message: The indicated order is invalid. Source: MyApplication Target Site: Void FindFormAndActivate (MyApplication.MDIParentForm, System.String, System.Object) Stack Trace: in MyApplication.UtilityClass.FindFormAndActivate (MDIParentForm frmMDIParentForm, String formName, Object parameter AttributeMindApp .DashboardAlerts.utAlerts_MouseClick (object sender, MouseEventArgs e) in System.Windows.Forms.Control.OnMouseClick (MouseEventArgs e) in System.Windows.Forms.Control.WmMouseUp (Message & m, MouseButtons button, Int32 clicks) in System.Windows .Forms.Control.WndProc (Message & m) in System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m) in System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m) in System.Windows. FormsNativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

, . ? , , , . , , . , a la Application.ThreadException += new ThreadExceptionEventHandler(HandleError);, HandleError - , . , , .

+5
2

, , , .

UtilityClass.SendEmail(shortNTID,
                   "admin@mydomain.com",
                   new string[] { "support@mydomain.com" },
                   "MyApplication error has occured for user: " +
                        shortNTID + " (Main).",
                   "Message: " + ex.Message.ToString() +
                   " Source: " + ex.Source.ToString() +
                   " Target Site: " + ex.TargetSite.ToString() +
                   " Stack Trace: " + ex.StackTrace.ToString() +
                   " MyVar1 Value: " + MyVar1.ToString() +
                   " MyVar2 Value: " + MyVar2.ToString() +
                   " MyVar3 Value: " + MyVar3.ToString());

Edit:

, , , . , ThreadException, , . ; . , :

public class CustomException : Exception
{
    public string MyVar1 { get; private set; }
    public string MyVar2 { get; private set; }
    public Exception OriginalException { get; private set; }

    public CustomException(Exception original, string myVar1, string myVar2)
    {
        MyVar1 = myVar1;
        MyVar2 = myVar2;
        OriginalException = original;
    }
}

, :

try
{
    //code that might throw exceptions
}
catch (Exception e)
{
    throw new CustomException(e, myVar1, myVar2);
}

, , OriginalException, () .

+3

StackTrace , . , .

:. , (.. ), .

+3

All Articles