Exemple #1
0
        protected void ParseException(LoggingEvent loggingEvent, Dictionary <string, object> resultDictionary)
        {
            if (FixedFields.ContainsFlag(FixFlags.Exception))
            {
                var exception       = loggingEvent.ExceptionObject;
                var exceptionString = loggingEvent.GetExceptionString();

                // If exceptionString is empty - no exception exists at all.
                // Because GetExceptionString() returns exceptionString if exists or exception.ToString().
                if (!string.IsNullOrEmpty(exceptionString))
                {
                    resultDictionary["Exception"] = exceptionString;

                    if (SerializeObjects && exception != null)
                    {
                        resultDictionary["ExceptionObject"] = JsonSerializableException.Create(exception);
                    }
                }
            }
        }
Exemple #2
0
        protected void ParseMessage(LoggingEvent loggingEvent, Dictionary <string, object> resultDictionary)
        {
            if (FixedFields.ContainsFlag(FixFlags.Message))
            {
                resultDictionary["Message"] = loggingEvent.RenderedMessage;

                // Added special handling of the MessageObject since it may be an exception.
                // Exception Types require specialized serialization to prevent serialization exceptions.
                if (SerializeObjects && loggingEvent.MessageObject != null && !(loggingEvent.MessageObject is string))
                {
                    if (loggingEvent.MessageObject is Exception exceptionObject)
                    {
                        resultDictionary["MessageObject"] = JsonSerializableException.Create(exceptionObject);
                    }
                    else
                    {
                        resultDictionary["MessageObject"] = loggingEvent.MessageObject;
                    }
                }
            }
        }
Exemple #3
0
        public static JsonSerializableException Create(Exception exception)
        {
            if (exception == null)
            {
                return(null);
            }

            var serializable = new JsonSerializableException
            {
                Type                             = exception.GetType().FullName,
                Message                          = exception.Message,
                HelpLink                         = exception.HelpLink,
                Source                           = exception.Source,
                StackTrace                       = exception.StackTrace,
                TargetSite                       = exception.TargetSite != null?exception.TargetSite.ToString() : null,
                                            Data = exception.Data
            };

            if (exception.InnerException != null)
            {
                serializable.InnerException = Create(exception.InnerException);
            }
            return(serializable);
        }