protected override void OnWrite(LogEntry entry, ImmutableCountedStack <LogSection> context)
        {               //****************************************
            string SourceAssembly = null, SourceFullType = null, SourceShortType = null, SourceMethod = null;

            object[] Arguments;

            var IndentLevel   = context.Count;
            var OutputBuilder = _OutputBuilder;

            //****************************************

            if (entry.Source != null)
            {
                var DeclaringType = entry.Source.DeclaringType;

                while (DeclaringType != null && DeclaringType.IsNestedPrivate && DeclaringType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length != 0)
                {
                    DeclaringType = DeclaringType.DeclaringType;
                }

                if (DeclaringType == null)
                {
                    DeclaringType = entry.Source.DeclaringType;
                }

                SourceAssembly  = DeclaringType.Assembly.GetName().Name;
                SourceFullType  = DeclaringType.FullName;
                SourceShortType = DeclaringType.Name;
                SourceMethod    = entry.Source.Name;
            }

            var RelativeTime = entry.Timestamp - LogManager.StartTime;

            Arguments = new object[] { entry.Timestamp, DateTime.MinValue.Add(RelativeTime > TimeSpan.Zero ? RelativeTime : TimeSpan.Zero), SourceAssembly, SourceFullType, SourceShortType, SourceMethod, entry.Severity, entry.Text };

            OutputBuilder.AppendFormat(CultureInfo.InvariantCulture, OutputFormatPre, Arguments);

            IndentTo(IndentLevel);

            OutputBuilder.AppendFormat(CultureInfo.InvariantCulture, OutputFormatPost, Arguments);

            if (entry is ExceptionLogEntry ExceptionEntry)
            {
                foreach (var EntryLine in ExceptionEntry.Exception.ToString().AsSpan().Split(Environment.NewLine.AsSpan(), false))
                {
                    OutputBuilder.AppendLine();

                    OutputBuilder.AppendFormat(CultureInfo.InvariantCulture, OutputFormatPre, Arguments);

                    IndentTo(IndentLevel);

                    OutputBuilder.Append(EntryLine);
                }
            }

            _Writer.WriteLine(OutputBuilder.ToString());

            OutputBuilder.Length = 0;

            _Writer.Flush();
        }
Esempio n. 2
0
 public FullLogEntry(LogEntry entry, ImmutableCountedStack <LogSection> context, Action callback)
 {
     Entry    = entry;
     Context  = context;
     Callback = callback;
 }