예제 #1
0
        /// <summary>
        /// Report a list of exceptions to Bugsnag with other per-request or per-session data
        /// </summary>
        /// <param name="exList">The list of exceptions to report</param>
        /// <param name="userId">An ID representing the current application's user.  If this isn't set
        /// this defaults to sessionId if available</param>
        /// <param name="context">The context that is currently active in the application</param>
        /// <param name="extraData">Data that will be sent as meta-data along with every error</param>
        public void Notify(List<System.Exception> exList, string userId, string context, object extraData)
        {
            //  Add an event for this exception list:
            List<Event> events = new List<Event>();
            events.Add(ProcessExceptions(exList, context, userId, extraData));

            //  Send the notification:
            ErrorNotification notification = new ErrorNotification()
            {
                Api_Key = this.apiKey,
                Events = events
            };

            SendNotification(notification, this.useSSL);
        }
예제 #2
0
        /// <summary>
        /// Sends current set of events to BugSnag via a JSON post
        /// </summary>
        /// <param name="notification">The notification to send</param>
        /// <param name="useSSL">Indicates the post should use SSL when sending JSON data</param>
        private void SendNotification(ErrorNotification notification, bool useSSL)
        {
            string serializedJSON = notification.SerializeToString();

            //  Create a byte array:
            byte[] byteArray = Encoding.UTF8.GetBytes(serializedJSON);

            //  Post JSON to server:
            WebRequest request;
            if(useSSL)
                request = WebRequest.Create(httpsUrl);
            else
                request = WebRequest.Create(httpUrl);

            request.Method = WebRequestMethods.Http.Post;
            request.ContentType = "application/json";
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            //  Get the response.  See https://bugsnag.com/docs/notifier-api for response codes
            var response = request.GetResponse();
        }
예제 #3
0
        /// <summary>
        /// Gathers information for the last error (if any error is available) 
        /// and reports it to BugSnag using information from the application
        /// configuration file and other defaults
        /// </summary>
        /// <param name="extraData">Any extra data to pass when reporting this error</param>
        public void Notify(object extraData)
        {
            //  If we're a web application, we can report errors automagically
            if(HttpContext.Current != null)
            {
                //  If we have errors...
                if (HttpContext.Current.AllErrors != null && HttpContext.Current.AllErrors.Any())
                {
                    //  ... go through all of the errors and report them
                    List<Event> events = new List<Event>();
                    events.Add(ProcessExceptions(
                        HttpContext.Current.AllErrors.ToList(),
                        HttpContext.Current.Request.Path,
                        GetDefaultUserId(),
                        extraData)
                    );

                    //  Send the notification:
                    ErrorNotification notification = new ErrorNotification()
                    {
                        Api_Key = this.apiKey,
                        Events = events
                    };

                    SendNotification(notification, this.useSSL);
                }
            }

            //  If we're not a web application, we're SOL ATM (call another method)
        }