Example #1
0
        public override void Format(ref TraceEntry traceEntry, FormatWriter formatWriter)
        {
            ColorCategory color = ColorCategory.None;

            if (formatWriter.IsColorEnabled)
            {
                color = TraceLevelToColorCategory(traceEntry.TraceLevel);
            }

            int entryIndentLevel = formatWriter.IndentLevel + RelativeIndentLevel;

            entryIndentLevel = Math.Min(entryIndentLevel, MaxIndentLevel);

            formatWriter.BeginEntry(entryIndentLevel);

            if (IncludeDate)
            {
                formatWriter.WriteDate(traceEntry.TimestampUtc, ColorCategory.Debug);
            }
            if (IncludeTimestamp)
            {
                formatWriter.WriteTimestamp(traceEntry.TimestampUtc, ColorCategory.Detail);
            }
            formatWriter.WriteField(TraceLevelToLabel(traceEntry.TraceLevel), color, 7);
            formatWriter.WriteAbbreviatedTypeName(traceEntry.TracerName, ColorCategory.Debug, 36);
            formatWriter.WriteField(traceEntry.Message.Trim(), color);
            if (traceEntry.Details != null)
            {
                ColorCategory detailColor = color == ColorCategory.Debug ? ColorCategory.Debug : ColorCategory.Detail;
                formatWriter.WriteLines(traceEntry.Details.ToString(), detailColor, 1);
            }

            formatWriter.EndEntry();
        }
        /// <inheritdoc />
        public override void Format(ref LoggerEntry entry, FormatWriter formatWriter)
        {
            ColorCategory color = ColorCategory.None;

            if (formatWriter.IsColorEnabled)
            {
                color = LogLevelToColorCategory(entry.LogLevel);
            }

            int entryIndentLevel = formatWriter.IndentLevel + RelativeIndentLevel;

            entryIndentLevel = Math.Min(entryIndentLevel, MaxIndentLevel);

            formatWriter.BeginEntry(entryIndentLevel);

            if (IncludeDate)
            {
                formatWriter.WriteDate(entry.TimestampUtc, ColorCategory.Debug);
            }
            if (IncludeTimestamp)
            {
                formatWriter.WriteTimestamp(entry.TimestampUtc, ColorCategory.Detail);
            }

            formatWriter.WriteField(LogLevelToLabel(entry.LogLevel), color, 7);
            formatWriter.WriteAbbreviatedTypeName(entry.CategoryName, ColorCategory.Debug, 36);

            if (IncludeEventId)
            {
                formatWriter.WriteField(entry.EventId.ToString(), color, 6);
            }

            string message = entry.DefaultFormatter(entry.State, null);

            formatWriter.WriteField(message.Trim(), color);
            if (entry.Exception != null)
            {
                ColorCategory detailColor = color == ColorCategory.Debug ? ColorCategory.Debug : ColorCategory.Detail;
                formatWriter.WriteLines(entry.Exception.ToString(), detailColor, 1);
            }

            formatWriter.EndEntry();
        }