Beispiel #1
0
        private static string BuildMessage(InfoCardBaseException ie)
        {
            Exception ex        = ie;
            String    errString = ex.Message + "\n";

            if (null != ex.InnerException)
            {
                while (null != ex.InnerException)
                {
                    errString += String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                               SR.GetString(SR.InnerExceptionTraceFormat),
                                               ex.InnerException.Message);
                    ex = ex.InnerException;
                }
                errString += String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                           SR.GetString(SR.CallStackTraceFormat),
                                           ie.ToString());
            }
            else
            {
                if (!String.IsNullOrEmpty(Environment.StackTrace))
                {
                    errString += String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                               SR.GetString(SR.CallStackTraceFormat),
                                               Environment.StackTrace);
                }
            }

            return(errString);
        }
Beispiel #2
0
        public static void TraceAndLogException(Exception e)
        {
            bool shouldLog           = false;
            bool isInformational     = false;
            InfoCardBaseException ie = e as InfoCardBaseException;

            //
            // We only log if this is an infocard exception that hasnt been previous logged,
            // and isnt the user cancelled exception.
            //
            if (null != ie && !(ie is UserCancelledException) && !ie.Logged)
            {
                shouldLog = true;
            }
            if (shouldLog)
            {
                //
                // If this is the parent of a previously logged exception then log as
                // informational.
                // If one of the children is UserCancelled, don't log at all
                //
                Exception current = ie.InnerException;
                while (null != current)
                {
                    if (current is UserCancelledException)
                    {
                        shouldLog = false;
                        break;
                    }
                    else if (current is InfoCardBaseException)
                    {
                        if ((current as InfoCardBaseException).Logged)
                        {
                            isInformational = true;
                        }
                    }
                    current = current.InnerException;
                }
            }
            if (shouldLog)
            {
                EventLogEntryType logType = isInformational ? EventLogEntryType.Information : EventLogEntryType.Error;
                string            message = ie.Message;
                if (!isInformational)
                {
                    message = BuildMessage(ie);
                }
                LogEvent((EventCode)ie.NativeHResult, message, logType);
            }
            TraceException(e);
        }
Beispiel #3
0
        private static string BuildMessage(InfoCardBaseException ie)
        {
            Exception innerException = ie;
            string    str            = innerException.Message + "\n";

            if (innerException.InnerException != null)
            {
                while (innerException.InnerException != null)
                {
                    str            = str + string.Format(CultureInfo.CurrentUICulture, Microsoft.InfoCards.SR.GetString("InnerExceptionTraceFormat"), new object[] { innerException.InnerException.Message });
                    innerException = innerException.InnerException;
                }
                return(str + string.Format(CultureInfo.CurrentUICulture, Microsoft.InfoCards.SR.GetString("CallStackTraceFormat"), new object[] { ie.ToString() }));
            }
            if (!string.IsNullOrEmpty(Environment.StackTrace))
            {
                str = str + string.Format(CultureInfo.CurrentUICulture, Microsoft.InfoCards.SR.GetString("CallStackTraceFormat"), new object[] { Environment.StackTrace });
            }
            return(str);
        }
Beispiel #4
0
        public static void TraceAndLogException(Exception e)
        {
            bool flag  = false;
            bool flag2 = false;
            InfoCardBaseException ie = e as InfoCardBaseException;

            if (((ie != null) && !(ie is UserCancelledException)) && !ie.Logged)
            {
                flag = true;
            }
            if (flag)
            {
                for (Exception exception2 = ie.InnerException; exception2 != null; exception2 = exception2.InnerException)
                {
                    if (exception2 is UserCancelledException)
                    {
                        flag = false;
                        break;
                    }
                    if ((exception2 is InfoCardBaseException) && (exception2 as InfoCardBaseException).Logged)
                    {
                        flag2 = true;
                    }
                }
            }
            if (flag)
            {
                EventLogEntryType type    = flag2 ? EventLogEntryType.Information : EventLogEntryType.Error;
                string            message = ie.Message;
                if (!flag2)
                {
                    message = BuildMessage(ie);
                }
                LogEvent((EventCode)ie.NativeHResult, message, type);
            }
        }
        private static string BuildMessage(InfoCardBaseException ie)
        {

            Exception ex = ie;
            String errString = ex.Message + "\n";

            if (null != ex.InnerException)
            {
                while (null != ex.InnerException)
                {
                    errString += String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                         SR.GetString(SR.InnerExceptionTraceFormat),
                                         ex.InnerException.Message);
                    ex = ex.InnerException;
                }
                errString += String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                         SR.GetString(SR.CallStackTraceFormat),
                                         ie.ToString());

            }
            else
            {
                if (!String.IsNullOrEmpty(Environment.StackTrace))
                {
                    errString += String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                            SR.GetString(SR.CallStackTraceFormat),
                                            Environment.StackTrace);
                }
            }

            return errString;

        }