Exemplo n.º 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();
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public override void Format(ref LoggerBeginScopeEntry <object> entry, FormatWriter formatWriter)
        {
            formatWriter.BeginEntry();

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

            formatWriter.WriteField("Begin", ColorCategory.Detail, 7);
            formatWriter.WriteAbbreviatedTypeName(entry.CategoryName, ColorCategory.Debug, 36);

            _reflectionFormatter.FormatObject(entry.State, formatWriter);

            formatWriter.EndEntry();
        }
Exemplo n.º 4
0
            public override void Format(ref MessageEntry entry, FormatWriter formatWriter)
            {
                formatWriter.BeginEntry(0);
                formatWriter.WriteTimestamp(entry.Timestamp);

                var buf = formatWriter.FieldBuffer;

                buf.Clear();
                buf.Append('[');
                if (entry.MessageId.HasValue)
                {
                    buf.Append(entry.MessageId.Value);
                }
                else
                {
                    buf.Append('?');
                }
                buf.Append(']');
                formatWriter.WriteField(buf);

                formatWriter.WriteField(entry.Text);
                formatWriter.EndEntry();
            }
Exemplo n.º 5
0
        /// <inheritdoc />
        public override void Format(ref HttpRequestEntry entry, FormatWriter formatWriter)
        {
            StringBuilder buf = formatWriter.FieldBuffer;

            formatWriter.BeginEntry(0);

            // RequestNumber
            buf.Clear();
            buf.Append(entry.RequestNumber);
            buf.Append('>');
            formatWriter.WriteField(buf, ColorCategory.Markup, 3);

            formatWriter.WriteTimestamp(entry.RequestStarted, ColorCategory.Detail);

            formatWriter.WriteField(entry.Method, ColorCategory.Info, 3);
            formatWriter.WriteField(entry.Uri, ColorCategory.Important);

            FormatterHelper.FormatHeaders(formatWriter, entry.RequestHeaders);

            formatWriter.WriteLine(); // Extra line break for readability
            formatWriter.EndEntry();

            formatWriter.IndentLevel++;
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public override void Format(ref HttpResponseEntry entry, FormatWriter formatWriter)
        {
            StringBuilder buf = formatWriter.FieldBuffer;

            formatWriter.IndentLevel--;
            formatWriter.BeginEntry(0);

            // RequestNumber
            buf.Clear();
            buf.Append(entry.RequestNumber);
            buf.Append('<');
            formatWriter.WriteField(buf, ColorCategory.Markup, 3);

            formatWriter.WriteTimestamp(entry.RequestCompleted, ColorCategory.Detail);

            // Ttfb
            buf.Clear();
            buf.AppendPadZeroes(entry.Ttfb.Seconds, 2);
            buf.Append('.');
            buf.AppendPadZeroes(entry.Ttfb.Milliseconds, 3);
            buf.Append('s');
            formatWriter.WriteField(buf, ColorCategory.Info);

            // Determine response color from HTTP status code
            ColorCategory responseColorCategory = ColorCategory.None;

            if (formatWriter.IsColorEnabled)
            {
                var statusCode = entry.HttpStatusCode;
                if ((statusCode >= 200) && (statusCode < 300))
                {
                    responseColorCategory = ColorCategory.Success;
                }
                else if ((statusCode >= 300) && (statusCode < 400))
                {
                    responseColorCategory = ColorCategory.Important;
                }
                else if (statusCode >= 500)
                {
                    responseColorCategory = ColorCategory.Error;
                }
                else
                {
                    responseColorCategory = ColorCategory.Warning;
                }
            }

            formatWriter.WriteField(entry.Method, ColorCategory.Info, 3);
            formatWriter.WriteField(entry.Uri, responseColorCategory);
            formatWriter.WriteLine();

            // HTTP status line
            formatWriter.WriteLinePrefix(formatWriter.IndentLevel + 1);
            formatWriter.WriteText("  HTTP/1.1 ", ColorCategory.Detail);
            buf.Clear();
            buf.Append(entry.HttpStatusCode);
            formatWriter.WriteText(buf, 0, buf.Length, responseColorCategory);
            formatWriter.WriteSpaces(1);
            formatWriter.WriteText(entry.HttpReasonPhrase, ColorCategory.Detail);
            formatWriter.WriteLine();

            FormatterHelper.FormatHeaders(formatWriter, entry.ResponseHeaders);

            formatWriter.WriteLine(); // Extra line break for readability
            formatWriter.EndEntry();
        }