Esempio n. 1
0
        private void Send(Notification notification)
        {
            try
            {
                //  Post JSON to server:
                var request = WebRequest.Create(Config.EndpointUrl);

                request.Method = WebRequestMethods.Http.Post;
                request.ContentType = "application/json";
                request.Proxy = DetectedProxy;

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(notification, JsonSettings);
                    streamWriter.Write(json);
                    streamWriter.Flush();
                }
                request.GetResponse().Close();
            }
            catch (Exception e)
            {
                Logger.Warning("Bugsnag failed to send error report with exception: " + e.ToString());

                // Deliberate empty catch for now

                // Must never double fault - i.e. can't leak an exception from an exception handler
                // Also the caller might have just wanted to report an "information" bugsnag and we
                // certainly don't want to fault then

                // However, "offline" handling should be addressed. I.e. bugsnags should be queued
                // until network is available and sent then, see
                // https://github.com/bugsnag/bugsnag-dotnet/issues/31
            }
        }
        private Notification CreateNotificationBase()
        {
            var notifierInfo = new NotifierInfo
            {
                Name = Notifier.Name,
                Version = Notifier.Version,
                Url = Notifier.Url.AbsoluteUri
            };

            var notification = new Notification
            {
                ApiKey = Config.ApiKey,
                Notifier = notifierInfo,
                Events = new List<EventInfo>()
            };
            return notification;
        }