示例#1
0
        private void RenderProperties(KeyValuePair <string, object>[] properties, LogEvent logEvent)
        {
            if (Utils.Any <KeyValuePair <string, object> >(properties))
            {
                IPropertyRenderer renderer = null;
                bool hasRenderers          = _RendererMap != null;
                var  eventProperties       = (logEvent.Properties = logEvent.Properties ?? new Dictionary <string, object>((properties?.Length ?? 1) + (_ContextProviders?.Length ?? 0)));
                foreach (var property in properties)
                {
                    renderer = null;
                    if (property.Value != null)
                    {
                        if (hasRenderers)
                        {
                            renderer = _RendererMap.GetRenderer(property.Value.GetType());
                        }
                        else if (_DefaultExceptionRenderer != null && property.Value is Exception)
                        {
                            renderer = _DefaultExceptionRenderer;
                        }
                    }

                    if (renderer != null)
                    {
                        eventProperties[property.Key] = renderer.RenderValue(property.Value);
                    }
                    else
                    {
                        eventProperties[property.Key] = property.Value;
                    }
                }
            }
        }
示例#2
0
        protected static void AddProperty(IDictionary <string, object> properties, string propertyName, object value, ITypeRendererMap rendererMap)
        {
            if (!properties.ContainsKey(propertyName))
            {
                IPropertyRenderer renderer = null;

                if (rendererMap != null && value != null)
                {
                    renderer = rendererMap.GetRenderer(value.GetType());
                }

                if (renderer != null)
                {
                    properties[propertyName] = renderer.RenderValue(value);
                }
                else
                {
                    properties[propertyName] = value;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Returns a string representation of an exception using the renderers provided in the constructor. If not appropriate renderer is found, the exceptions ToString method result is returned.
        /// </summary>
        /// <param name="exception">The exception to format.</param>
        /// <returns>A string containing the formatted reprsentation of <paramref name="exception"/>.</returns>
        protected virtual string RenderException(Exception exception)
        {
            if (exception == null)
            {
                return(null);
            }
            if (_ExceptionRenderers == null)
            {
                return(exception.ToString());
            }

            var renderer = _ExceptionRenderers.GetRenderer(exception.GetType());

            if (renderer == null)
            {
                return(exception.ToString());
            }
            else
            {
                return((renderer.RenderValue(exception) ?? String.Empty).ToString());
            }
        }