Ejemplo n.º 1
0
        public RaygunMessage BuildMessage(Exception exception, LoggingEvent loggingEvent, Dictionary <string, string> userCustomData,
                                          IMessageFilter exceptionFilter, IMessageFilter renderedMessageFilter, IgnoredDataSettings ignoredFieldSettings, string customApplicationVersion)
        {
            var raygunMessageBuilder = Mindscape.Raygun4Net.RaygunMessageBuilder.New;

            var httpContext = _httpContextFactory();

            if (httpContext != null && httpContext.Instance != null)
            {
                LogLog.Debug(DeclaringType, "RaygunAppender: Setting http details on the raygun message from http context");

                var messageOptions = new RaygunRequestMessageOptions(
                    ignoredFieldSettings.IgnoredSensitiveFieldNames,
                    ignoredFieldSettings.IgnoredQueryParameterNames,
                    ignoredFieldSettings.IgnoredFormNames,
                    ignoredFieldSettings.IgnoredHeaderNames,
                    ignoredFieldSettings.IgnoredCookieNames,
                    ignoredFieldSettings.IgnoredServerVariableNames)
                {
                    IsRawDataIgnored = ignoredFieldSettings.IsRawDataIgnored
                };

                raygunMessageBuilder.SetHttpDetails(httpContext.Instance, messageOptions);
            }

            raygunMessageBuilder
            .SetExceptionDetails(exception)
            .SetClientDetails()
            .SetTags(ExtractTags(loggingEvent.GetProperties()))
            .SetUser(ExtractAffectedUser(loggingEvent.GetProperties()))
            .SetEnvironmentDetails()
            .SetMachineName(Environment.MachineName)
            .SetVersion(GetApplicationVersion(customApplicationVersion))
            .SetUserCustomData(FilterRenderedMessageInUserCustomData(userCustomData, renderedMessageFilter));

            var raygunMessage = raygunMessageBuilder.Build();

            if (exception != null)
            {
                if (raygunMessage.Details.Error != null)
                {
                    raygunMessage.Details.Error.Message = exceptionFilter.ApplyTo(exception.Message);
                }
            }
            else
            {
                LogLog.Debug(DeclaringType, "RaygunAppender: No exception object found in error, creating raygun error message from the rendered message and calling class");
                raygunMessage.Details.Error = new RaygunErrorMessage
                {
                    Message   = renderedMessageFilter.ApplyTo(loggingEvent.RenderedMessage),
                    ClassName = loggingEvent.LocationInformation.ClassName
                };
            }

            return(raygunMessage);
        }
        private Dictionary <string, string> FilterRenderedMessageInUserCustomData(Dictionary <string, string> userCustomData, IMessageFilter renderedMessageFilter)
        {
            if (userCustomData.ContainsKey(UserCustomDataBuilder.UserCustomDataKey.RenderedMessage))
            {
                var oldValue = userCustomData[UserCustomDataBuilder.UserCustomDataKey.RenderedMessage];
                userCustomData[UserCustomDataBuilder.UserCustomDataKey.RenderedMessage] = renderedMessageFilter.ApplyTo(oldValue);
            }

            return(userCustomData);
        }