コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ErrorReportDTO" /> class.
        /// </summary>
        /// <param name="reportId">Unique identifier for this error report.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="contextCollections">The context collections.</param>
        public ErrorReportDTO(string reportId, ExceptionDTO exception, ContextCollectionDTO[] contextCollections)
        {
            if (reportId == null)
            {
                throw new ArgumentNullException("reportId");
            }
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            if (contextCollections == null)
            {
                throw new ArgumentNullException("contextCollections");
            }
            if (reportId.Contains(" ") || reportId.Length > 30)
            {
                throw new ArgumentException(
                          string.Format(
                              "reportId must be 30 or less characters and should be alphanumeric only. Your id '{0}' is {1} chars.",
                              reportId, reportId.Length));
            }

            ContextCollections = contextCollections;
            Exception          = exception;
            ReportId           = reportId;
            ReportVersion      = "1.0";
            CreatedAtUtc       = DateTime.UtcNow;
        }
コード例 #2
0
        /// <summary>
        ///     Copy the .NET exception information into our DTO.
        /// </summary>
        /// <param name="source">Exception to copy from</param>
        /// <param name="destination">Model to put the information in.</param>
        public static void Copy(Exception source, ExceptionDTO destination)
        {
            var culture   = Thread.CurrentThread.CurrentCulture;
            var uiCulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                var evt = new ManualResetEventSlim(false);

                // in a seperate thread to not get any side effects due to the culture change.
                ThreadPool.QueueUserWorkItem(x =>
                {
                    //TODO: wont work for some exceptions (where texts are preloaded). We need to use Google Translate.
                    Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = English;
                    try
                    {
                        destination.FullName     = source.GetType().FullName;
                        destination.Name         = source.GetType().Name;
                        destination.Namespace    = source.GetType().Namespace;
                        destination.AssemblyName = source.GetType().Assembly.FullName;
                        destination.Message      = source.Message;

                        var baseTypes           = GetBaseClasses(source);
                        destination.BaseClasses = baseTypes.ToArray();
                        destination.StackTrace  = source.StackTrace;
                        destination.Properties  = GetProperties(source);

                        try
                        {
                            destination.Everything = Serializer.Serialize(source);
                        }
                        catch
                        {
                            destination.Everything = source.ToString();
                        }

                        if (source.InnerException != null)
                        {
                            destination.InnerException = new ExceptionDTO(source.InnerException);
                        }
                    }
                    catch
                    {
                        Thread.CurrentThread.CurrentCulture   = culture;
                        Thread.CurrentThread.CurrentUICulture = uiCulture;
                    }
                    evt.Set();
                });
                evt.Wait();

                if (destination.StackTrace == null)
                {
                    Debug.WriteLine("StackTrace can be empty (SoapException), but it's not likely");
                    destination.StackTrace = "";
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = uiCulture;
            }
        }