コード例 #1
0
        private void RenderAllRenderers(LogEventInfo logEvent, StringBuilder builder)
        {
            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < this.Renderers.Count; i++)
            {
                LayoutRenderer renderer = this.Renderers[i];
                try
                {
                    renderer.Render(builder, logEvent);
                }
                catch (Exception exception)
                {
                    //also check IsErrorEnabled, otherwise 'MustBeRethrown' writes it to Error

                    //check for performance
                    if (InternalLogger.IsWarnEnabled || InternalLogger.IsErrorEnabled)
                    {
                        InternalLogger.Warn(exception, "Exception in '{0}.Append()'", renderer.GetType().FullName);
                    }

                    if (exception.MustBeRethrown())
                    {
                        throw;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Renders the layout for the specified logging event by invoking layout renderers
        /// that make up the event.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        /// <returns>The rendered layout.</returns>
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            if (IsFixedText)
            {
                return(this.fixedText);
            }

            string cachedValue;

            if (logEvent.TryGetCachedLayoutValue(this, out cachedValue))
            {
                return(cachedValue);
            }

            int initialSize = this.maxRenderedLength;

            if (initialSize > MaxInitialRenderBufferLength)
            {
                initialSize = MaxInitialRenderBufferLength;
            }

            var builder = new StringBuilder(initialSize);

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < this.Renderers.Count; i++)
            {
                LayoutRenderer renderer = this.Renderers[i];
                try
                {
                    renderer.Render(builder, logEvent);
                }
                catch (Exception exception)
                {
                    //also check IsErrorEnabled, otherwise 'MustBeRethrown' writes it to Error

                    //check for performance
                    if (InternalLogger.IsWarnEnabled || InternalLogger.IsErrorEnabled)
                    {
                        InternalLogger.Warn(exception, "Exception in '{0}.Append()'", renderer.GetType().FullName);
                    }

                    if (exception.MustBeRethrown())
                    {
                        throw;
                    }
                }
            }

            if (builder.Length > this.maxRenderedLength)
            {
                this.maxRenderedLength = builder.Length;
            }

            string value = builder.ToString();

            logEvent.AddCachedLayoutValue(this, value);
            return(value);
        }
コード例 #3
0
        /// <summary>
        /// set in Session and test
        /// </summary>
        /// <param name="key">set with this key</param>
        /// <param name="value">set this value</param>
        /// <param name="expected">expected</param>
        /// <param name="appSettingLayoutRenderer"></param>
        /// <remarks>IRenderable is internal</remarks>
        private void ExecTest(string key, object value, object expected, LayoutRenderer appSettingLayoutRenderer)
        {
            Session[key] = value;

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
コード例 #4
0
 private static LayoutRenderer ConvertToLiteral(LayoutRenderer renderer)
 {
     return(new LiteralLayoutRenderer(renderer.Render(LogEventInfo.CreateNullEvent())));
 }
コード例 #5
0
        public void Render(XElement imageXml, Stream output)
        {
            var image = renderer.Render(builder.Build(imageXml));

            image.Save(output, ImageFormat.Png);
        }