Exemplo n.º 1
0
        /// <summary>
        /// Process a list of exceptions into an event
        /// </summary>
        /// <param name="exList">A list of exceptions</param>
        /// <param name="Context">The context for the event</param>
        /// <param name="UserId">The userId for the event</param>
        /// <param name="ExtraData">Extra data to annotate on the event</param>
        /// <returns></returns>
        private Event ProcessExceptions(List<System.Exception> exList, string Context, string UserId, object extraData)
        {
            //  Create an event to return
            Event retval = new Event()
            {
                AppVersion = this.applicationVersion,
                Context = Context,
                OSVersion = this.OSVersion,
                ReleaseStage = this.releaseStage,
                UserId = UserId,
                ExtraData = extraData
            };

            //  Our list of exceptions:
            List<Bugsnag.Library.Data.Exception> exceptions = new List<Bugsnag.Library.Data.Exception>();

            //  For each exception passed...
            foreach(System.Exception ex in exList)
            {
                //  ... Create a list of stacktraces
                //  This may not be the best way to get this information:
                //  http://blogs.msdn.com/b/jmstall/archive/2005/03/20/399287.aspx
                var stacktraces = (from item in new System.Diagnostics.StackTrace(ex, true).GetFrames()
                                   select new Stacktrace()
                                   {
                                       File = item.GetFileName() ?? item.GetType().Name ?? "N/A",
                                       LineNumber = item.GetFileLineNumber(),
                                       Method = item.GetMethod().Name
                                   }).ToList();

                //  Add a new exception, and use the stacktrace list:
                exceptions.Add(new Bugsnag.Library.Data.Exception()
                {
                    ErrorClass = ex.TargetSite.Name,
                    Message = ex.Message,
                    Stacktrace = stacktraces
                });
            }

            //  Set our list of exceptions
            retval.Exceptions = exceptions;

            //  Return the event:
            return retval;
        }