//public IActionResult Index()
        //{
        //    throw new Exception("Yikes an Error!!!");
        //    //return View();
        //}

        public async Task <IActionResult> Index()
        {
            try
            {
                throw new Exception("Yikes an Error!!!");
                //return View();
            }
            catch (Exception ex)
            {
                var msg = new RaygunMessage();

                msg.Details = new RaygunMessageDetails
                {
                    User    = RayGunUtils.BuildRayGunIdentifierMessage(HttpContext.User),
                    Error   = RaygunErrorMessageBuilder.Build(ex),
                    Request = await RaygunAspNetCoreRequestMessageBuilder.Build(HttpContext, new RaygunRequestMessageOptions())
                };

                var rgClient = _rgProvider.GetClient(new RaygunSettings(), HttpContext);
                await rgClient.SendInBackground(msg);

                return(View());
                //return new JsonResult(new ExceptionResponse
                //{
                //    ErrorId = Guid.NewGuid(),
                //    Message = ex.Message
                //}); ;
            }
        }
        /// <summary>
        /// Posts a RaygunMessage to the Raygun.io api endpoint.
        /// </summary>
        /// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
        /// set to a valid DateTime and as much of the Details property as is available.</param>
        public override void Send(RaygunMessage raygunMessage)
        {
            try
            {
                bool canSend = OnSendingMessage(raygunMessage) && CanSend(raygunMessage);
                if (canSend)
                {
                    var message = SimpleJson.SerializeObject(raygunMessage);
                    WebClientHelper.Send(message, _apiKey, ProxyCredentials);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
                }
                catch
                {
                    // ignored
                }

                if (RaygunSettings.Settings.ThrowOnError)
                {
                    throw;
                }
            }
        }
Exemplo n.º 3
0
        public void SetTimeStamp()
        {
            DateTime      time    = new DateTime(2015, 2, 16);
            RaygunMessage message = _builder.SetTimeStamp(time).Build();

            Assert.AreEqual(time, message.OccurredOn);
        }
Exemplo n.º 4
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(DeclaringType, string.Format("RaygunAppender: Received Logging Event with Logging Level '{0}'", loggingEvent.Level));

            Exception exception = ResolveLoggedExceptionObject(loggingEvent);

            if (exception != null || !OnlySendExceptions)
            {
                if (Retries > 0)
                {
                    LogLog.Debug(DeclaringType, "RaygunAppender: Retries are enabled, checking that throw on errors has been enabled, or can be overridden");
                    RaygunThrowOnErrorsMustBeEnabled();
                }

                RaygunMessage raygunMessage = BuildRaygunMessageToSend(exception, loggingEvent);

                if (raygunMessage == null)
                {
                    LogLog.Warn(DeclaringType, "RaygunAppender: Failed to send due to an invalid RaygunMessage object");
                }
                else
                {
                    if (SendInBackground)
                    {
                        SendErrorToRaygunInBackground(raygunMessage);
                    }
                    else
                    {
                        SendErrorToRaygun(raygunMessage);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void SetVersion_Null()
        {
            _builder.SetVersion(null);
            RaygunMessage message = _builder.Build();

            Assert.AreEqual("Not supplied", message.Details.Version);
        }
Exemplo n.º 6
0
        public void MessageWithUserInfoFromBuild()
        {
            RaygunMessage message = _client.ExposeBuildMessage(_exception, null, null, new RaygunIdentifierMessage("Robbie Robot"));

            Assert.AreEqual("Robbie Robot", message.Details.User.Identifier);
            Assert.IsFalse(message.Details.User.IsAnonymous);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Posts a RaygunMessage to the Raygun api endpoint.
        /// </summary>
        /// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
        /// set to a valid DateTime and as much of the Details property as is available.</param>
        public void Send(RaygunMessage raygunMessage)
        {
            if (ValidateApiKey())
            {
                bool canSend = OnSendingMessage(raygunMessage);
                if (canSend)
                {
                    string message = null;

                    try
                    {
                        message = SimpleJson.SerializeObject(raygunMessage);
                    }
                    catch (Exception ex)
                    {
                        RaygunClient.Log(string.Format("Error serializing raygun message: {0}", ex.Message));
                    }

                    if (message != null)
                    {
                        SendMessage(message);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private RaygunMessage BuildRaygunMessageToSend(Exception exception, LoggingEvent loggingEvent)
        {
            LogLog.Debug(DeclaringType, "RaygunAppender: Building UserCustomData dictionary");
            var userCustomData = _userCustomDataBuilder.Build(loggingEvent);

            LogLog.Debug(DeclaringType, "RaygunAppender: Building Raygun message");

            var exceptionFilter       = ActivateInstanceOfMessageFilter(ExceptionFilter);
            var renderedMessageFilter = ActivateInstanceOfMessageFilter(RenderedMessageFilter);

            var ignoredFieldSettings = new IgnoredDataSettings(IgnoredFormNames, IgnoredHeaderNames, IgnoredCookieNames,
                                                               IgnoredServerVariableNames, IgnoredQueryParameterNames, IgnoredSensitiveFieldNames, IsRawDataIgnored);

            RaygunMessage raygunMessage = null;

            try
            {
                raygunMessage = _raygunMessageBuilder.BuildMessage(exception, loggingEvent, userCustomData, exceptionFilter,
                                                                   renderedMessageFilter, ignoredFieldSettings, ApplicationVersion);
            }
            catch (Exception ex)
            {
                LogLog.Error(DeclaringType, "RaygunAppender: Failed to build RaygunMessage", ex);
            }

            return(raygunMessage);
        }
 public void Initialize(RaygunMessage raygunMessage)
 {
     if (raygunMessage.Details.UserCustomData == null)
     {
         raygunMessage.Details.UserCustomData = new Dictionary <string, object>();
     }
     raygunMessage.Details.UserCustomData["initializerTestData"] = "true";
 }
Exemplo n.º 10
0
        public void MessageWithUser()
        {
            _client.User = "******";

            RaygunMessage message = _client.ExposeBuildMessage(_exception);

            Assert.AreEqual("Robbie Robot", message.Details.User.Identifier);
        }
 protected override void Append(LoggingEvent loggingEvent)
 {
     if (IsErrorOrGreaterWithExceptionObject(loggingEvent))
     {
         RaygunMessage message = _messageBuilderFactory.CreateBuilder().SetException(loggingEvent.ExceptionObject).SetLog4NetInfo(loggingEvent).Build();
         _clientExecutor.Execute(client => client.SendInBackground(message));
     }
 }
Exemplo n.º 12
0
 protected override bool CanSend(RaygunMessage message)
 {
     if (message != null && message.Details != null && message.Details.Response != null)
     {
         return(!GetSettings().ExcludedStatusCodes.Contains(message.Details.Response.StatusCode));
     }
     return(true);
 }
Exemplo n.º 13
0
        public void StripHttpUnhandledExceptionByDefault()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Exemplo n.º 14
0
        public void StripTargetInvocationExceptionByDefault()
        {
            TargetInvocationException wrapper = new TargetInvocationException(_exception);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Exemplo n.º 15
0
        public void SetCustomApplicationVersion()
        {
            _client.ApplicationVersion = "Custom Version";

            RaygunMessage message = _client.ExposeBuildMessage(_exception);

            Assert.AreEqual("Custom Version", message.Details.Version);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            //Include the log level as a tag.
            var tags = _tags.Concat(new [] { logEvent.Level.ToString() }).ToList();

            var properties = logEvent.Properties
                             .Select(pv => new { Name = pv.Key, Value = RaygunPropertyFormatter.Simplify(pv.Value) })
                             .ToDictionary(a => a.Name, b => b.Value);

            // Add the message
            properties.Add("RenderedLogMessage", logEvent.RenderMessage(_formatProvider));
            properties.Add("LogMessageTemplate", logEvent.MessageTemplate.Text);

            // Create new message
            var raygunMessage = new RaygunMessage
            {
                OccurredOn = logEvent.Timestamp.UtcDateTime
            };

            // Add exception when available
            if (logEvent.Exception != null)
            {
                raygunMessage.Details.Error = RaygunErrorMessageBuilder.Build(logEvent.Exception);
            }

            // Add user when requested
            if (!String.IsNullOrWhiteSpace(_userNameProperty) &&
                logEvent.Properties.ContainsKey(_userNameProperty) &&
                logEvent.Properties[_userNameProperty] != null)
            {
                raygunMessage.Details.User = new RaygunIdentifierMessage(logEvent.Properties[_userNameProperty].ToString());
            }

            // Add version when requested
            if (!String.IsNullOrWhiteSpace(_applicationVersionProperty) &&
                logEvent.Properties.ContainsKey(_applicationVersionProperty) &&
                logEvent.Properties[_applicationVersionProperty] != null)
            {
                raygunMessage.Details.Version = logEvent.Properties[_applicationVersionProperty].ToString();
            }

            // Build up the rest of the message
            raygunMessage.Details.Environment    = new RaygunEnvironmentMessage();
            raygunMessage.Details.Tags           = tags;
            raygunMessage.Details.UserCustomData = properties;
            raygunMessage.Details.MachineName    = Environment.MachineName;

            if (HttpContext.Current != null)
            {
                // Request message is built here instead of raygunClient.Send so RequestMessageOptions have to be constructed here
                var requestMessageOptions = new RaygunRequestMessageOptions(_ignoredFormFieldNames, Enumerable.Empty <string>(), Enumerable.Empty <string>(), Enumerable.Empty <string>());
                raygunMessage.Details.Request = RaygunRequestMessageBuilder.Build(HttpContext.Current.Request, requestMessageOptions);
            }

            // Submit
            //_client.SendInBackground(raygunMessage);
            _client.Send(raygunMessage);
        }
Exemplo n.º 17
0
        public void StripMultipleWrapperExceptions()
        {
            HttpUnhandledException    wrapper  = new HttpUnhandledException("Something went wrong", _exception);
            TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper2);

            Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Exemplo n.º 18
0
        public void ResponseIsNullForNonWebExceptions()
        {
            NullReferenceException exception = new NullReferenceException("The thing is null");

            _builder.SetExceptionDetails(exception);
            RaygunMessage message = _builder.Build();

            Assert.IsNull(message.Details.Response);
        }
Exemplo n.º 19
0
        public void DontStripIfNoInnerException()
        {
            TargetInvocationException wrapper = new TargetInvocationException(null);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.Reflection.TargetInvocationException", message.Details.Error.ClassName);
            Assert.IsNull(message.Details.Error.InnerError);
        }
Exemplo n.º 20
0
        protected bool CanSend(RaygunMessage message)
        {
            if (message?.Details?.Response != null)
            {
                return(!RaygunSettings.Settings.ExcludedStatusCodes.Contains(message.Details.Response.StatusCode));
            }

            return(true);
        }
Exemplo n.º 21
0
        public void DontStripIfNoInnerException()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException();

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.Web.HttpUnhandledException", message.Details.Error.ClassName);
            Assert.IsNull(message.Details.Error.InnerError);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            var tags = new List <String> {
                logEvent.Level.ToString()
            };

            var properties = logEvent.Properties
                             .Select(pv => new { Name = pv.Key, Value = RaygunPropertyFormatter.Simplify(pv.Value) })
                             .ToDictionary(a => a.Name, b => b.Value);

            // Add the message
            properties.Add("Message", logEvent.RenderMessage(_formatProvider));
            properties.Add("MessageTemplate", logEvent.MessageTemplate.Text);

            // Create new message
            var raygunMessage = new RaygunMessage
            {
                OccurredOn = logEvent.Timestamp.UtcDateTime
            };

            // Add exception when available
            if (logEvent.Exception != null)
            {
                raygunMessage.Details.Error = new RaygunErrorMessage(logEvent.Exception);
            }

            // Add user when requested
            if (!String.IsNullOrWhiteSpace(_userNameProperty) &&
                logEvent.Properties.ContainsKey(_userNameProperty) &&
                logEvent.Properties[_userNameProperty] != null)
            {
                raygunMessage.Details.User = new RaygunIdentifierMessage(logEvent.Properties[_userNameProperty].ToString());
            }

            // Add version when requested
            if (!String.IsNullOrWhiteSpace(_applicationVersionProperty) &&
                logEvent.Properties.ContainsKey(_applicationVersionProperty) &&
                logEvent.Properties[_applicationVersionProperty] != null)
            {
                raygunMessage.Details.Version = logEvent.Properties[_applicationVersionProperty].ToString();
            }

            // Build up the rest of the message
            raygunMessage.Details.Environment    = new RaygunEnvironmentMessage();
            raygunMessage.Details.Tags           = tags;
            raygunMessage.Details.UserCustomData = properties;
            raygunMessage.Details.MachineName    = Environment.MachineName;

            if (HttpContext.Current != null)
            {
                raygunMessage.Details.Request = new RaygunRequestMessage(HttpContext.Current.Request, null);
            }

            // Submit
            _client.SendInBackground(raygunMessage);
        }
Exemplo n.º 23
0
        public void SetVersion()
        {
            IRaygunMessageBuilder builder = _builder.SetVersion("Custom Version");

            Assert.AreEqual(_builder, builder);

            RaygunMessage message = _builder.Build();

            Assert.AreEqual("Custom Version", message.Details.Version);
        }
Exemplo n.º 24
0
        public void StripSpecifiedWrapperException()
        {
            _client.AddWrapperExceptions(new Type[] { typeof(WrapperException) });

            WrapperException wrapper = new WrapperException(_exception);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Exemplo n.º 25
0
        public void RemoveWrapperExceptions()
        {
            _client.RemoveWrapperExceptions(typeof(TargetInvocationException));

            TargetInvocationException wrapper = new TargetInvocationException(_exception);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.Reflection.TargetInvocationException", message.Details.Error.ClassName);
        }
Exemplo n.º 26
0
        public void HandleUnknownStatusCodeFromHttpException()
        {
            HttpException exception = new HttpException(1, "?");

            _builder.SetExceptionDetails(exception);
            RaygunMessage message = _builder.Build();

            Assert.IsNotNull(message.Details.Response);
            Assert.AreEqual(1, message.Details.Response.StatusCode);
            Assert.IsNull(message.Details.Response.StatusDescription);
        }
Exemplo n.º 27
0
        public void IsAnonymousDefault()
        {
            RaygunIdentifierMessage user = new RaygunIdentifierMessage("Robbie Robot");

            Assert.IsFalse(user.IsAnonymous);

            _client.User = "******";
            RaygunMessage message = _client.ExposeBuildMessage(_exception);

            Assert.IsFalse(message.Details.User.IsAnonymous);
        }
Exemplo n.º 28
0
        public void GetStatusCodeFromHttpException()
        {
            HttpException exception = new HttpException(404, "the file is gone");

            _builder.SetExceptionDetails(exception);
            RaygunMessage message = _builder.Build();

            Assert.IsNotNull(message.Details.Response);
            Assert.AreEqual(404, message.Details.Response.StatusCode);
            Assert.AreEqual("NotFound", message.Details.Response.StatusDescription);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Posts a RaygunMessage to the Raygun.io api endpoint.
        /// </summary>
        /// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
        /// set to a valid DateTime and as much of the Details property as is available.</param>
        public override void Send(RaygunMessage raygunMessage)
        {
            if (ValidateApiKey())
            {
                bool canSend = OnSendingMessage(raygunMessage) && CanSend(raygunMessage);
                if (canSend)
                {
                    using (var client = new WebClient())
                    {
                        client.Headers.Add("X-ApiKey", _apiKey);
                        client.Headers.Add("content-type", "application/json; charset=utf-8");
                        client.Encoding = System.Text.Encoding.UTF8;

                        if (WebRequest.DefaultWebProxy != null)
                        {
                            Uri proxyUri = WebRequest.DefaultWebProxy.GetProxy(new Uri(RaygunSettings.Settings.ApiEndpoint.ToString()));

                            if (proxyUri != null && proxyUri.AbsoluteUri != RaygunSettings.Settings.ApiEndpoint.ToString())
                            {
                                client.Proxy = new WebProxy(proxyUri, false);

                                if (ProxyCredentials == null)
                                {
                                    client.UseDefaultCredentials = true;
                                    client.Proxy.Credentials     = CredentialCache.DefaultCredentials;
                                }
                                else
                                {
                                    client.UseDefaultCredentials = false;
                                    client.Proxy.Credentials     = ProxyCredentials;
                                }
                            }
                        }

                        try
                        {
                            var message = SimpleJson.SerializeObject(raygunMessage);
                            client.UploadString(RaygunSettings.Settings.ApiEndpoint, message);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));

                            if (RaygunSettings.Settings.ThrowOnError)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
        // Returns true if the message can be sent, false if the sending is canceled.
        protected bool OnSendingMessage(RaygunMessage raygunMessage)
        {
            bool result = true;
            EventHandler <RaygunSendingMessageEventArgs> handler = SendingMessage;

            if (handler != null)
            {
                RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage);
                handler(this, args);
                result = !args.Cancel;
            }
            return(result);
        }
Exemplo n.º 31
0
        public void Send(RaygunMessage raygunMessage)
        {
            ThreadPool.QueueUserWorkItem(c =>
            {
                using (var client = new WebClient())
                {
                    client.Headers.Add("X-ApiKey", _apiKey);
                    client.Encoding = Encoding.UTF8;

                    try
                    {
                        var builder = new StringBuilder();
                        Json.Json.Serialize(raygunMessage, builder);
                        client.UploadString(RaygunSettings.Settings.ApiEndpoint, builder.ToString());
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}",
                                                      ex.Message));
                    }
                }
            });
        }
Exemplo n.º 32
0
 private RaygunMessageBuilder()
 {
     _raygunMessage = new RaygunMessage();
 }