Ejemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="AirbrakeNotice"/> from the the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <param name="info"> Additional info to send to Airbrake.</param>
        /// <returns></returns>
        public AirbrakeNotice Notice(AirbrakeError error, Dictionary<string, string> info = null)
        {
            this.log.Debug(f => f("{0}.Notice({1})", GetType(), error));

            var notice = new AirbrakeNotice
            {
                ApiKey = Configuration.ApiKey,
                Error = error,
                Notifier = Notifier,
                ServerEnvironment = ServerEnvironment,
            };

            MethodBase catchingMethod = (error != null)
                                            ? error.CatchingMethod
                                            : null;

            AddContextualInformation(notice, catchingMethod, info);

            return notice;
        }
Ejemplo n.º 2
0
 public AirbrakeNotice BuildNotice(AirbrakeError error)
 {
     return this.Builder.Notice(error);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="AirbrakeNotice"/> from the the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public AirbrakeNotice Notice(AirbrakeError error)
        {
            this.log.Debug(f => f("{0}.Notice({1})", GetType(), error));

            var notice = new AirbrakeNotice
            {
                ApiKey = Configuration.ApiKey,
                Error = error,
                Notifier = Notifier,
                ServerEnvironment = ServerEnvironment,
            };

            if (HttpContext.Current != null)
            {
                Assembly assembly = Assembly.GetExecutingAssembly();

                notice.Request = new AirbrakeRequest(HttpContext.Current.Request.Url, assembly.CodeBase)
                {
                    Params = BuildParams().ToArray(),
                    Session = BuildSession().ToArray(),
                    CgiData = BuildCgiData().ToArray(),
                };
            }

            return notice;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a <see cref="AirbrakeNotice"/> from the the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public AirbrakeNotice Notice(AirbrakeError error)
        {
            this.log.Debug(f => f("{0}.Notice({1})", GetType(), error));

            var notice = new AirbrakeNotice
            {
                ApiKey = Configuration.ApiKey,
                Error = error,
                Notifier = Notifier,
                ServerEnvironment = ServerEnvironment,
            };

            MethodBase catchingMethod = (error != null)
                                            ? error.CatchingMethod
                                            : null;

            AddInfoFromHttpContext(notice, catchingMethod);

            return notice;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="AirbrakeError"/> from the the specified exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <returns>
        /// A <see cref="AirbrakeError"/>, created from the the specified exception.
        /// </returns>
        public AirbrakeError ErrorFromException(Exception exception)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            this.log.Debug(f => f("{0}.Notice({1})", GetType(), exception.GetType()), exception);

            var error = new AirbrakeError
            {
                Class = exception.GetType().FullName,
                Message = exception.GetType().Name + ": " + exception.Message,
                Backtrace = BuildBacktrace(exception).ToArray(),
            };

            return error;
        }
Ejemplo n.º 6
0
        public void MinimalNoticeGeneratesValidXml()
        {
            var error = new AirbrakeError
            {
                Class   = "TestError",
                Message = "something blew up",

                Backtrace = new[]
                {
                    new AirbrakeTraceLine("unknown.cs", 0)
                    {
                        Method = "unknown"
                    }
                }
            };

            var notice = new AirbrakeNotice
            {
                ApiKey = "123456",
                Error  = error,

                Notifier = new AirbrakeNotifier
                {
                    Name    = "sharpbrake",
                    Version = "2.2.2.0",
                    Url     = "https://github.com/airbrake/SharpBrake"
                },

                ServerEnvironment = new AirbrakeServerEnvironment("staging")
                {
                    ProjectRoot = "/test",
                },
            };

            var serializer = new CleanXmlSerializer<AirbrakeNotice>();
            var xml        = serializer.ToXml(notice);

            AirbrakeValidator.ValidateSchema(xml);
        }
Ejemplo n.º 7
0
        public void MaximalNoticeGeneratesValidXml()
        {
            var error  = new AirbrakeError
            {
                Class   = "TestError",
                Message = "something blew up",

                Backtrace = new[]
                {
                    new AirbrakeTraceLine("unknown.cs", 0)
                    {
                        Method = "unknown"
                    }
                }
            };

            var notice = new AirbrakeNotice
            {
                ApiKey = "123456",
                Error  = error,

                Request = new AirbrakeRequest(new Uri("http://example.com/"), GetType().FullName)
                {
                    Action    = "MaximalNoticeGeneratesValidXml",
                    Component = "MyApp.HomeController",
                    Url       = "http://example.com/myapp",

                    CgiData = new[]
                    {
                        new AirbrakeVar("REQUEST_METHOD", "POST"),
                    },

                    Params = new[]
                    {
                        new AirbrakeVar("Form.Key1", "Form.Value1"),
                    },

                    Session = new[]
                    {
                        new AirbrakeVar("UserId", "1"),
                    },
                },

                Notifier = new AirbrakeNotifier
                {
                    Name    = "sharpbrake",
                    Version = "2.2.2.0",
                    Url     = "https://github.com/airbrake/SharpBrake",
                },

                ServerEnvironment = new AirbrakeServerEnvironment("staging")
                {
                    ProjectRoot = "/test",
                },
            };

            var serializer = new CleanXmlSerializer<AirbrakeNotice>();
            var xml        = serializer.ToXml(notice);

            AirbrakeValidator.ValidateSchema(xml);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a <see cref="AirbrakeNotice"/> from the the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public AirbrakeNotice BuildNotice(AirbrakeError error)
        {
            _log.Debug(f => f("{0}.Notice({1})", GetType(), error));

            var notice = new AirbrakeNotice
            {
                ApiKey            = Configuration.ApiKey,
                Error             = error,
                Notifier          = Notifier,
                ServerEnvironment = ServerEnvironment,
            };

            MethodBase catchingMethod = error != null ? error.CatchingMethod : null;

            AddContextualInformation(notice, catchingMethod);

            return notice;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a <see cref="AirbrakeNotice"/> from the the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <param name="extraParams">extra data for adding the params in airbrake notice </param>
        /// <returns></returns>
        public AirbrakeNotice Notice(AirbrakeError error, IEnumerable<KeyValuePair<string, string>> extraParams = null)
        {
            this.log.Debug(f => f("{0}.Notice({1})", GetType(), error));

            var notice = new AirbrakeNotice
            {
                ApiKey = Configuration.ApiKey,
                Error = error,
                Notifier = Notifier,
                ServerEnvironment = ServerEnvironment,
            };

            MethodBase catchingMethod = (error != null)
                                            ? error.CatchingMethod
                                            : null;

            AddContextualInformation(notice, catchingMethod, extraParams);

            return notice;
        }