Render environmental information related to logging events.
Inheritance: INLogConfigurationItem, ISupportsInitialize, IRenderable
Exemplo n.º 1
0
        private static bool CanBeConvertedToLiteral(LayoutRenderer lr)
        {
            foreach(IRenderable renderable in ObjectGraph.AllChilds<IRenderable>(lr))
            {
                if (renderable.GetType() == typeof(SimpleLayout))
                    continue;

                if (!renderable.GetType().IsDefined(typeof(AppDomainFixedOutputAttribute), false))
                    return false;
            }

            return true;
        }
Exemplo n.º 2
0
        private static LayoutRenderer ApplyWrappers(LoggingConfiguration cfg, LayoutRenderer lr, List<LayoutRenderer> orderedWrappers)
        {
            for (int i = orderedWrappers.Count - 1; i >= 0; --i)
            {
                var newRenderer = (WrapperLayoutRendererBase)orderedWrappers[i];
                InternalLogger.Trace("Wrapping {0} with {1}", lr.GetType().Name, newRenderer.GetType().Name);
                if (CanBeConvertedToLiteral(lr))
                {
                    lr = ConvertToLiteral(cfg, lr);
                }

                newRenderer.Inner = new SimpleLayout(string.Empty, new[] { lr });
                lr = newRenderer;
            }

            return lr;
        }
Exemplo n.º 3
0
 internal SimpleLayout(LayoutRenderer[] renderers, string text, ConfigurationItemFactory configurationItemFactory)
 {
     this.configurationItemFactory = configurationItemFactory;
     this.SetRenderers(renderers, text);
 }
Exemplo n.º 4
0
        internal void SetRenderers(LayoutRenderer[] renderers, string text)
        {
            this.Renderers = new ReadOnlyCollection<LayoutRenderer>(renderers);
            if (this.Renderers.Count == 1 && this.Renderers[0] is LiteralLayoutRenderer)
            {
                this.fixedText = ((LiteralLayoutRenderer)this.Renderers[0]).Text;
            }
            else
            {
                this.fixedText = null;
            }

            this.layoutText = text;
        }
        /// <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);
        }
Exemplo n.º 6
0
        internal void SetRenderers(LayoutRenderer[] renderers, string text)
        {
            this.Renderers = new ReadOnlyCollection<LayoutRenderer>(renderers);

            if (this.Renderers.Count == 0)
            {
                //todo fixedText = null is also used if the text is fixed, but is a empty renderers not fixed?
                this.fixedText = null;
                this.StackTraceUsage = StackTraceUsage.None;
            }
            else if (this.Renderers.Count == 1 && this.Renderers[0] is LiteralLayoutRenderer)
            {
                this.fixedText = ((LiteralLayoutRenderer)this.Renderers[0]).Text;
                this.StackTraceUsage = StackTraceUsage.None;
            }
            else
            {
                this.fixedText = null;
                this.StackTraceUsage = this.Renderers.OfType<IUsesStackTrace>().DefaultIfEmpty().Max(usage => usage == null ? StackTraceUsage.None : usage.StackTraceUsage);
            }

            this.layoutText = text;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Adds an element with the specified key and value to this LayoutRendererDictionary.
 /// </summary>
 /// <param name="key">
 /// The string key of the element to add.
 /// </param>
 /// <param name="value">
 /// The LayoutRenderer value of the element to add.
 /// </param>
 public virtual void Add(string key, LayoutRenderer value)
 {
     this.Dictionary.Add(key, value);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Determines whether this LayoutRendererDictionary contains a specific value.
 /// </summary>
 /// <param name="value">
 /// The LayoutRenderer value to locate in this LayoutRendererDictionary.
 /// </param>
 /// <returns>
 /// true if this LayoutRendererDictionary contains an element with the specified value;
 /// otherwise, false.
 /// </returns>
 public virtual bool ContainsValue(LayoutRenderer value)
 {
     foreach (LayoutRenderer item in this.Dictionary.Values)
     {
         if (item == value)
             return true;
     }
     return false;
 }
Exemplo n.º 9
0
 private static LayoutRenderer ConvertToLiteral(LayoutRenderer renderer)
 {
     return new LiteralLayoutRenderer(renderer.Render(LogEventInfo.CreateNullEvent()));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleLayout"/> class.
 /// </summary>
 /// <param name="text">The layout string to view.</param>
 /// <param name="renderers">renderers</param>
 public SimpleLayout(string text, LayoutRenderer[] renderers)
 {
     _layoutText = text;
     SetRenderers(renderers);
 }
Exemplo n.º 11
0
 private void SetRenderers(LayoutRenderer[] renderers)
 {
     Renderers = new ReadOnlyCollection<LayoutRenderer>(renderers);
     if (Renderers.Count == 1 && this.Renderers[0] is LiteralLayoutRenderer)
         _fixedText = ((LiteralLayoutRenderer)Renderers[0]).Text;
     else
         _fixedText = null;
 }
Exemplo n.º 12
0
 internal SimpleLayout(LayoutRenderer[] renderers, string text, NLogFactories nlogFactories)
 {
     this.nlogFactories = nlogFactories;
     this.SetRenderers(renderers, text);
 }
Exemplo n.º 13
0
 private static LayoutRenderer ConvertToLiteral(LoggingConfiguration cfg, LayoutRenderer renderer)
 {
     var closeReq = ObjectGraph.DeepInitialize(renderer, cfg, LogManager.ThrowExceptions);
     string text = renderer.Render(LogEventInfo.CreateNullEvent());
     foreach (var item in closeReq)
         item.Close();
     return new LiteralLayoutRenderer(text);
 }