public override void Write(ParsedLayout layout, TextWriter tw, LoggerEvent evt)
            {
                PropertyTree data = this.GetDataTree(evt);

                IEnumerable <PropertyNode> nodes;

                if (string.IsNullOrWhiteSpace(this.Property))
                {
                    nodes = new [] { data };
                }
                else
                {
                    nodes = ApplyDataFilter(data);
                }

                foreach (var node in nodes)
                {
                    if (node.IsPropertyTree)
                    {
                        WriteNode((PropertyTree)node, layout, this.Property, tw, 0);
                    }
                    else
                    {
                        WriteCore(layout, node.Value, Property, tw);
                    }
                }
            }
 internal ConsoleTarget(ConsoleTargetBuilder builder)
 {
     this.pattern    = ParsedLayout.Parse(builder.Layout, builder.LayoutMode);
     this.Layout     = builder.Layout;
     this.LayoutMode = builder.LayoutMode;
     this.colorMappings.AddMany(builder.ColorMappings);
     this.colorMappings.MakeReadOnly();
     this.colorMappingsCache = this.colorMappings.GetEffectiveColors();
     this.console            = new BclConsoleWrapper();
 }
 static void WriteCore(ParsedLayout layout, object value, string property, TextWriter tw)
 {
     if (value == null)
     {
         layout.WriteVar(tw, property, "<null>", false);
     }
     else
     {
         bool escape = IsEscapedType(value.GetType());
         layout.WriteVar(tw, property, value.ToString(), escape);
     }
 }
            public sealed override void Write(ParsedLayout layout, TextWriter tw, LoggerEvent evt)
            {
                if (formatCache == null)
                {
                    formatCache = string.Concat('{', '0',
                                                Padding == 0 ? string.Empty : ("," + Padding),
                                                string.IsNullOrWhiteSpace(Format) ? string.Empty : (":" + Format),
                                                '}');
                }

                layout.WriteVar(tw, VarName,
                                string.Format(formatCache, Evaluate(evt)),
                                Escape);
            }
Esempio n. 5
0
 internal FileTarget(FileTargetBuilder builder, IServiceProvider sp)
     : base(builder)
 {
     this.CreateDirectories = builder.CreateDirectories;
     this.FileName          = builder.FileName;
     this.Mode                = builder.Mode;
     this.RolloverMode        = builder.Rollover.Mode;
     this.RolloverMaxFileSize = builder.Rollover.MaxFileSize;
     this.RolloverMaxAge      = builder.Rollover.MaxAge;
     this.Renderer            = builder.Renderer ?? builder.DefaultRenderer;
     this.Index               = -1;
     this.baseUri             = ((IUriContext)builder).BaseUri;
     this.fileNamePattern     = ParsedLayout.ParseFileName(this.FileName);
 }
            // TODO Generated output should be in prefix order
            void WriteNode(PropertyTree node,
                           ParsedLayout layout,
                           string prefix,
                           TextWriter tw,
                           int level)
            {
                if (level == 6 || !node.HasChildren)
                {
                    return;
                }

                string nodeName = node.Name;

                if (level == 0)
                {
                    nodeName = char.ToUpperInvariant(nodeName[0]) + nodeName.Substring(1);
                }
                string property = prefix + nodeName;

                StringBuilder s = new StringBuilder();

                foreach (var child in node.Children)
                {
                    if (child.IsPropertyTree)
                    {
                        WriteNode((PropertyTree)child, layout, property + ".", tw, level + 1);
                    }
                    else
                    {
                        s.Append(child.Name)
                        .Append("=")
                        .Append(child.Value)
                        .Append(s.Length > 0 ? "; " : string.Empty);
                    }
                }

                if (s.Length > 0)
                {
                    layout.WriteVar(tw, property, s.ToString(), false);
                }
            }
 public override void Write(ParsedLayout layout, TextWriter tw, LoggerEvent evt)
 {
     layout.WriteLine(tw);
 }
 public abstract void Write(ParsedLayout layout, TextWriter tw, LoggerEvent evt);
 internal TextRenderer(ParsedLayout layout,
                       Encoding encoding)
 {
     this.parsedLayout = layout;
     this.Encoding     = encoding;
 }