private static void RenderValue(RendererMap rendererMap, TextWriter writer, object value)
 {
     if (value is string)
     {
         writer.Write(value);
     }
     else
     {
         IObjectRenderer keyRenderer = rendererMap.Get(value.GetType());
         keyRenderer.RenderObject(rendererMap, value, writer);
     }
 }
        /// <summary>
        /// Render <paramref name="obj"/> into the <paramref name="writer"/>
        /// </summary>
        /// <param name="map">from <see cref="LoggingEvent.Repository"/></param>
        /// <param name="obj">value to be rendered</param>
        /// <param name="writer">writer to write obj to</param>
        public void RenderObject(RendererMap map, object obj, TextWriter writer)
        {
            foreach (var decorator in Decorators)
            {
                obj = decorator.Decorate(obj);
            }

            var renderer = Renderer
                           ?? (map == null ? null : map.Get(obj))
                           ?? JsonObjectRenderer.Default ?? map.DefaultRenderer;

            renderer.RenderObject(map, obj, writer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retorna una clase que puede representar en formato XML el cabezal de
        /// mensajes.
        /// </summary>
        /// <param name="renderingMap">Es un mapa con todas las clases que
        /// representan objetos.</param>
        /// <returns>Una clase que puede representar en formato XML el cabezal de
        /// mensajes.
        /// </returns>
        public override MessagingComponentXmlRendering XmlRendering(
            RendererMap renderingMap)
        {
            IObjectRenderer objectRendering = renderingMap.Get(typeof(MessageHeader));

            if (objectRendering == null)
            {
                // Add renderer to map.
                objectRendering = new MessageHeaderXmlRendering();
                renderingMap.Put(typeof(MessageHeader), objectRendering);
            }
            else
            if (!(objectRendering is MessageHeaderXmlRendering))
            {
                objectRendering = new MessageHeaderXmlRendering();
            }

            return(( MessagingComponentXmlRendering)objectRendering);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Serialize an object (last resort) into a string builder
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="sb"></param>
        /// <param name="map">log4net renderer map</param>
        protected virtual bool SerializeObject(Object obj, StringBuilder sb, RendererMap map)
        {
            if (obj == null)
            {
                return(false);
            }

            var customSerializer = map == null ? null : map.Get(obj) as ISerializer;

            if (customSerializer == null)
            {
                var dict = ObjToDict(obj, SaveType, TypeMemberName, Stringify, StringMemberName);
                SerializeDictionary(dict, sb, map);
            }
            else
            {
                var json = customSerializer.Serialize(obj, map);
                sb.Append(json);
            }

            return(true);
        }
 public ThrowableRenderer(RendererMap rendererMap)
 {
     this.fallback = rendererMap.Get(typeof(Throwable));
 }