public static JsonSerializableException Create(Exception exception)
        {
            if (exception == null)
                return null;

            var serializable = new JsonSerializableException
            {
#if NET45
                HResult = exception.HResult,
#endif
                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 = JsonSerializableException.Create(exception.InnerException);
            }
            return serializable;
        }
        public static JsonSerializableException Create(Exception exception)
        {
            if (exception == null)
            {
                return(null);
            }

            var serializable = new JsonSerializableException
            {
#if NET45
                HResult = exception.HResult,
#endif
                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 = JsonSerializableException.Create(exception.InnerException);
            }
            return(serializable);
        }
Example #3
0
        protected void ParseException(LoggingEvent sourceLoggingEvent, Dictionary <string, object> resultDictionary)
        {
            if (FixedFields.ContainsFlag(FixFlags.Exception))
            {
                var exception       = sourceLoggingEvent.ExceptionObject;
                var exceptionString = sourceLoggingEvent.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);
                    }
                }
            }
        }
Example #4
0
        protected void ParseMessage(LoggingEvent sourceLoggingEvent, Dictionary <string, object> resultDictionary)
        {
            if (FixedFields.ContainsFlag(FixFlags.Message))
            {
                resultDictionary["Message"] = sourceLoggingEvent.RenderedMessage;

                // Added special handling of the MessageObject since it may be an exception.
                // Exception Types require specialized serialization to prevent serialization exceptions.
                if (SerializeObjects && sourceLoggingEvent.MessageObject != null && !(sourceLoggingEvent.MessageObject is string))
                {
                    var exceptionObject = sourceLoggingEvent.MessageObject as Exception;
                    if (exceptionObject != null)
                    {
                        resultDictionary["MessageObject"] = JsonSerializableException.Create(exceptionObject);
                    }
                    else
                    {
                        resultDictionary["MessageObject"] = sourceLoggingEvent.MessageObject;
                    }
                }
            }
        }