Exemple #1
0
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            if (obj == null)
            {
                writer.Write(SystemInfo.NullText);
            }
            PatientLogObject log = obj as PatientLogObject;

            if (log != null)
            {
                if (log.Execute == Enums.ExecuteEnumType.ENTERING)
                {
                    writer.Write("Entering {0} with parametsrs [ {1} ]...",
                                 log.Method,
                                 log.Parameter
                                 );
                }
                else
                {
                    writer.Write("Exiting {0} with return value [ {1} ]...",
                                 log.Method,
                                 log.Parameter
                                 );
                }
            }
            else
            {
                writer.Write(SystemInfo.NullText);
            }
        }
Exemple #2
0
 public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
 {
     if (obj is LogDatum)
     {
         RenderAppenderLogDatum((LogDatum)obj, writer);
     }
 }
Exemple #3
0
        /// <summary>
        /// It builds a XML representation of an ISO 8583 message.
        /// </summary>
        /// <param name="renderingMap">
        /// It's the renderer map (see log4net).
        /// </param>
        /// <param name="component">
        /// It's the ISO 8583 message.
        /// </param>
        /// <param name="indent">
        /// It's the indentation to be used.
        /// </param>
        /// <returns>
        /// A XML representation of an ISO 8583 message.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// If the <paramref name="component"/> isn't an ISO 8583 message.
        /// </exception>
        public override string DoRender(RendererMap renderingMap,
                                        MessagingComponent component, string indent)
        {
            if (!(component is Iso8583Message))
            {
                throw new ArgumentException(SR.ComponentIsNotAnISO8583Message, "component");
            }

            Iso8583Message message = ( Iso8583Message)component;

            StringBuilder render = new StringBuilder();

            render.Append(indent);
            render.Append("<");
            render.Append(XmlIso8583MessageTag);
            render.Append(" ");
            render.Append(XmlIso8583MessageTypeIdentifierAttr);
            render.Append("=\"");
            render.Append(message.MessageTypeIdentifier.ToString(CultureInfo.InvariantCulture));
            render.Append("\">");
            render.Append(Environment.NewLine);

            render.Append((( Message)message).XmlRendering(renderingMap).DoRender(
                              renderingMap, message, indent + "   "));

            render.Append(indent);
            render.Append("</");
            render.Append(XmlIso8583MessageTag);
            render.Append(">");
            render.Append(Environment.NewLine);

            return(render.ToString());
        }
Exemple #4
0
        /// Implementation of the IObjectRenderer interface. Called on when an
        /// exception is logged.
        public void RenderObject(RendererMap map, object obj, System.IO.TextWriter writer)
        {
            Exception ex = obj as Exception;

            for (; ex != null; ex = ex.InnerException)
            {
                if (ex is COMException && ex.Message.StartsWith("<?xml"))
                {
                    writer.WriteLine();
                    writer.Write("HFMException message XML contents:");
                    writer.Write(YAML.XML.ConvertXML(ex.Message));
                }
                else
                {
                    writer.Write(ex.GetType().Name);
                    writer.Write(": ");
                    writer.Write(ex.Message);
                }
                if (ex.InnerException != null)
                {
                    writer.WriteLine();
                }
                else if (_logHierarchy.Root.Level.CompareTo(log4net.Core.Level.Fine) < 0)
                {
                    writer.WriteLine();
                    writer.WriteLine("Backtrace:");
                    writer.Write(ex.StackTrace);
                }
            }
        }
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            if (obj == null)
            {
                writer.Write(SystemInfo.NullText);
            }
            ApplicationUserLogObject log = obj as ApplicationUserLogObject;

            if (log != null)
            {
                if (log.ExecuteType == Enums.ExecuteEnumType.ENTERING)
                {
                    writer.Write("Entering {0} with parameters [ Id={1} User Name={2}]...",
                                 log.Method,
                                 log.ApplicationUser.Id,
                                 log.ApplicationUser.UserName
                                 );
                }
                else
                {
                    writer.Write("Entering {0} with parameters [ Id={1} User Name={2} ]...",
                                 log.Method,
                                 log.ApplicationUser.Id,
                                 log.ApplicationUser.UserName);
                }
            }
            else
            {
                writer.Write(SystemInfo.NullText);
            }
        }
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            var ex = obj as ReflectionTypeLoadException;

            if (ex != null)
            {
                foreach (var loaderException in ex.LoaderExceptions)
                {
                    writer.WriteLine(loaderException);
                }
            }

            var db = obj as MySqlException;

            if (db != null)
            {
                writer.Write($"ErrorCode = {db.Code}, ");
                writer.Write(db.ToString());
            }

            var e = obj as Exception;

            if (e != null)
            {
                var mysql = e.Chain().OfType <MySqlException>().FirstOrDefault();
                if (mysql != null)
                {
                    writer.Write($"MySql ErrorCode = {mysql.Code}, ");
                }
                writer.Write(e);
            }
        }
    public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
    {
        var invocation = (IInvocation)obj;
        var builder    = new StringBuilder();

        builder.AppendFormat(
            "Invoking Method: {0} --> '{1}' with parameters (",
            invocation.Method.DeclaringType != null
                   ? invocation.Method.DeclaringType.FullName : "{Unknown Type}",
            invocation.Method);
        var parameters = invocation.Method
                         .GetParameters()
                         .Zip(invocation.Arguments, (p, a) => new { Parameter = p, Argument = a })
                         .ToArray();
        var index = 0;

        foreach (var parameter in parameters)
        {
            builder.AppendFormat(
                "{0}: {1}",
                parameter.Parameter.Name,
                rendererMap.FindAndRender(parameter.Argument));
            if (++index < parameters.Length)
            {
                builder.Append(", ");
            }
        }
        builder.Append(")");
        writer.Write(builder.ToString());
    }
Exemple #8
0
        /// <summary>
        /// Serialize enumerables into a string builder
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="sb"></param>
        /// <param name="map">log4net renderer map</param>
        protected virtual bool SerializeArray(IEnumerable obj, StringBuilder sb, RendererMap map)
        {
            if (obj == null)
            {
                return(false);
            }

            sb.Append("[");

            bool first = true;

            foreach (var item in obj)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }

                Serialize(item, sb, map);
            }

            sb.Append("]");

            return(true);
        }
Exemple #9
0
        /// <summary></summary>
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            if (obj == null)
            {
                return;
            }

            var objAsString = obj as string;

            if (obj is string)
            {
                writer.Write(objAsString);
                return;
            }

            if (obj is LazyString)
            {
                writer.Write(obj.ToString());
                return;
            }

            var ns = obj.GetType().Namespace;

            if (!string.IsNullOrEmpty(ns) && (ns.StartsWith("log4net") || ns.StartsWith("Common.Logging")))
            {
                //if we get a log4net object, log4net will expect us to call ToString to get the format
                writer.Write(obj.ToString());
                return;
            }

            new Printers.ObjectPrinter(obj).PrintTo(writer);
        }
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            var ex = obj as Exception;

            if (ex == null)
            {
                // Shouldn't happen if only configured for the System.Exception type.
                rendererMap.DefaultRenderer.RenderObject(rendererMap, obj, writer);
            }
            else
            {
                rendererMap.DefaultRenderer.RenderObject(rendererMap, obj, writer);

                const int MAX_DEPTH    = 10;
                int       currentDepth = 0;

                var traversedExceptions = new List <Exception>();

                while (ex != null && currentDepth <= MAX_DEPTH && !traversedExceptions.Contains(ex))
                {
                    traversedExceptions.Add(ex);

                    this.RenderExceptionData(rendererMap, ex, writer, currentDepth);
                    ex = ex.InnerException;

                    currentDepth++;
                }
            }
        }
Exemple #11
0
        /// <summary></summary>
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            if (obj == null)
            {
                return;
            }

            var objAsString = obj as string;

            if (obj is string)
            {
                writer.Write(objAsString);
                return;
            }

            if (obj is LazyString)
            {
                writer.Write(obj.ToString());
                return;
            }

            if (obj.GetType().IsTypeFromLoggingFramework())
            {
                //if we get a log4net object, log4net will expect us to call ToString to get the format
                writer.Write(obj.ToString());
                return;
            }

            obj.DumpTo(writer);
        }
        private void RenderExceptionData(RendererMap rendererMap, Exception ex, TextWriter writer, int depthLevel)
        {
            var dataCount = ex.Data.Count;

            if (dataCount == 0)
            {
                return;
            }

            writer.WriteLine();

            writer.WriteLine($"Exception data on level {depthLevel} ({dataCount} items):");

            var currentElement = 0;

            foreach (DictionaryEntry entry in ex.Data)
            {
                currentElement++;

                writer.Write("[");
                ExceptionObjectLogger.RenderValue(rendererMap, writer, entry.Key);
                writer.Write("]: ");

                ExceptionObjectLogger.RenderValue(rendererMap, writer, entry.Value);

                if (currentElement < dataCount)
                {
                    writer.WriteLine();
                }
            }
        }
Exemple #13
0
 //--- Methods ---
 public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
 {
     if (obj is Exception)
     {
         writer.Write(((Exception)obj).GetCoroutineStackTrace());
     }
 }
 public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
 {
     for (Exception i = obj as Exception; i != null; i = i.InnerException)
     {
         this.WriteException(i, writer);
     }
 }
Exemple #15
0
    public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
    {
        var myList = obj as IList <MyClass>;

        if (myList != null)
        {
            try
            {
                int no = 1;
                foreach (MyClass entry in myList)
                {
                    writer.Write("Entry {0}: PropertyA={1} PropertyB={2}\n",
                                 no++,
                                 entry.PropertyA,
                                 entry.PropertyB);
                }
            }
            catch (NullReferenceException ex)
            {
                writer.Write(SystemInfo.NullText);
            }
        }
        else
        {
            new DefaultRenderer().RenderObject(rendererMap, obj, writer);
        }
    }
Exemple #16
0
        /// <summary>
        /// Serialize <paramref name="obj"/> to a JSON string
        /// </summary>
        /// <param name="obj">object to serialize</param>
        /// <param name="map">log4net renderer map</param>
        /// <returns>JSON string</returns>
        public object Serialize(object obj, RendererMap map)
        {
            var sb = new StringBuilder();

            Serialize(obj, sb, map);

            return(sb.ToString());
        }
Exemple #17
0
        /// <summary>
        /// Implementa el método requerido por log4net para personalizar la
        /// representación de un tipo de objetos en particular.
        /// </summary>
        /// <param name="renderingMap">
        /// Es el mapa de todos los objetos que representan objetos. Vea log4net.
        /// </param>
        /// <param name="obj">
        /// Es el objeto a representar.
        /// </param>
        /// <param name="writer">
        /// Es donde se representa el objeto.
        /// </param>
        public virtual void RenderObject(RendererMap renderingMap, object obj, TextWriter writer)
        {
            if (!(obj is MessagingComponent))
            {
                throw new ArgumentException(SR.ComponentIsNotAMessagingComponent, "obj");
            }

            writer.Write(DoRender(renderingMap, ( MessagingComponent)obj, string.Empty));
        }
Exemple #18
0
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            EligibilityAuditLogEntry entry = obj as EligibilityAuditLogEntry;

            if (entry != null)
            {
                AuditHashesToXml(entry.log_hash, entry.AAAs, new XmlTextWriter(writer));
            }
        }
Exemple #19
0
        public void RenderObject(RendererMap rendererMap, object obj, System.IO.TextWriter writer)
        {
            var dictionary = obj as IDictionary;

            if (dictionary == null)
            {
                writer.Write(SystemInfo.NullText);
            }
        }
Exemple #20
0
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            var thrown = obj as Exception;

            while (thrown != null)
            {
                RenderException(thrown, writer);
                thrown = thrown.InnerException;
            }
        }
Exemple #21
0
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            var exception = obj as Exception;

            while (exception != null)
            {
                WriteException(exception, writer);
                exception = exception.InnerException;
            }
        }
Exemple #22
0
            public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
            {
                var msgInfo = obj as SecsMessageLogInfo;

                if (msgInfo != null)
                {
                    writer.WriteLine($"EAP {(msgInfo.In ? "<<" : ">>")} EQP : [id=0x{msgInfo.SystemByte:X8}]");
                    msgInfo.Message.WriteTo(writer);
                }
            }
Exemple #23
0
        /// <summary>
        /// Retorna la representación XML en una cadena de caracteres de un campo
        /// de mensaje.
        /// </summary>
        /// <param name="renderingMap">
        /// Es el mapa de todos los objetos que representan objetos. Vea log4net.
        /// </param>
        /// <param name="component">
        /// Es el campo a ser representado en XML.
        /// </param>
        /// <param name="indent">
        /// Es la indentación a emplear en la representación XML.
        /// </param>
        /// <returns>
        /// Retorna una cadena de caracteres con la representación en XML
        /// del campo de mensaje.
        /// </returns>
        public override string DoRender(RendererMap renderingMap,
                                        MessagingComponent component, string indent)
        {
            if (!(component is Field))
            {
                throw new ArgumentException(SR.ComponentIsNotAField, "component");
            }

            Field         field  = ( Field)component;
            StringBuilder render = new StringBuilder();

            render.Append(indent);
            render.Append("<");
            render.Append(MessagingComponentXmlRendering.XmlFieldTag);
            render.Append(" ");
            render.Append(MessagingComponentXmlRendering.XmlNumberAttr);
            render.Append("=\"");
            render.Append(field.FieldNumber.ToString(CultureInfo.CurrentCulture));
            render.Append("\" ");
            render.Append(MessagingComponentXmlRendering.XmlTypeAttr);
            render.Append("=\"");

            if (field.Value is MessagingComponent)
            {
                render.Append(MessagingComponentXmlRendering.XmlComponentVal);
                render.Append("\">");
                render.Append(Environment.NewLine);
                render.Append((( MessagingComponent)(field.Value)).XmlRendering(
                                  renderingMap).DoRender(renderingMap,
                                                         (( MessagingComponent)(field.Value)), indent + "   "));
                render.Append(indent);
                render.Append("</");
                render.Append(MessagingComponentXmlRendering.XmlFieldTag);
                render.Append(">");
            }
            else
            {
                if (field is StringField)
                {
                    render.Append(MessagingComponentXmlRendering.XmlStringVal);
                }
                else
                {
                    render.Append(MessagingComponentXmlRendering.XmlBinaryVal);
                }
                render.Append("\" ");
                render.Append(MessagingComponentXmlRendering.XmlValueAttr);
                render.Append("=\"");
                render.Append(field.ToString());
                render.Append("\" />");
            }
            render.Append(Environment.NewLine);

            return(render.ToString());
        }
Exemple #24
0
 /// <summary>
 /// Construct the repository using specific properties
 /// </summary>
 /// <param name="properties">the properties to set for this repository</param>
 /// <remarks>
 /// <para>
 /// Initializes the repository with specified properties.
 /// </para>
 /// </remarks>
 protected LoggerRepositorySkeleton(PropertiesDictionary properties)
 {
     m_properties            = properties;
     m_rendererMap           = new RendererMap();
     m_pluginMap             = new PluginMap(this);
     m_levelMap              = new LevelMap();
     m_configurationMessages = EmptyCollection.Instance;
     m_configured            = false;
     AddBuiltinLevels();
     m_threshold = Level.All;
 }
Exemple #25
0
 public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
 {
     if (obj is Amazon.CloudWatch.Model.MetricDatum)
     {
         RenderAWSMetricDatum((Amazon.CloudWatch.Model.MetricDatum)obj, writer);
     }
     else if (obj is MetricDatum)
     {
         RenderAppenderMetricDatum((MetricDatum)obj, writer);
     }
 }
 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>
        /// Construct the repository using specific properties
        /// </summary>
        /// <param name="properties">the properties to set for this repository</param>
        /// <remarks>
        /// <para>
        /// Initializes the repository with specified properties.
        /// </para>
        /// </remarks>
        protected LoggerRepositorySkeleton(PropertiesDictionary properties)
        {
            m_properties  = properties;
            m_rendererMap = new RendererMap();
            m_pluginMap   = new PluginMap(this);
            m_levelMap    = new LevelMap();
            m_configured  = false;

            AddBuiltinLevels();

            // Don't disable any levels by default.
            m_threshold = Level.All;
        }
Exemple #28
0
        public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)
        {
            HttpRequestBase requestBase = obj as HttpRequestBase;

            if (null == requestBase)
            {
                return;
            }

            var renderedRequest = FormatRequest(requestBase);

            writer.WriteLine(renderedRequest);
        }
        public void RenderObject(RendererMap rendererMap, object obj, System.IO.TextWriter writer)
        {
            var exception = obj as Exception;

            if (exception != null)
            {
                writer.WriteLine(exception.ToDescriptiveString());
            }
            else
            {
                writer.Write(SystemInfo.NullText);
            }
        }
        /// <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);
        }