Esempio n. 1
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     foreach (var value in _structure.GetValues())
     {
         logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                          value.Key,
                                          value.Value));
     }
 }
Esempio n. 2
0
        private void FormatLoggerStructure(StringBuilder builder, ILoggerStructure structure, int level, bool bullet)
        {
            if (structure.Message != null)
            {
                builder.Append(structure.Message);
            }
            var values = structure.GetValues();

            if (values == null)
            {
                return;
            }
            var isFirst = true;

            foreach (var kvp in values)
            {
                builder.AppendLine();
                if (bullet && isFirst)
                {
                    builder.Append(' ', level * _indentation - 1)
                    .Append('-');
                }
                else
                {
                    builder.Append(' ', level * _indentation);
                }
                builder.Append(kvp.Key)
                .Append(": ");
                if (kvp.Value is IEnumerable && !(kvp.Value is string))
                {
                    foreach (var value in (IEnumerable)kvp.Value)
                    {
                        if (value is ILoggerStructure)
                        {
                            FormatLoggerStructure(
                                builder,
                                (ILoggerStructure)value,
                                level + 1,
                                bullet: true);
                        }
                        else
                        {
                            builder.AppendLine()
                            .Append(' ', (level + 1) * _indentation)
                            .Append(value);
                        }
                    }
                }
                else if (kvp.Value is ILoggerStructure)
                {
                    FormatLoggerStructure(
                        builder,
                        (ILoggerStructure)kvp.Value,
                        level + 1,
                        bullet: false);
                }
                else
                {
                    builder.Append(kvp.Value);
                }
                isFirst = false;
            }
        }