Ejemplo n.º 1
0
        int RenderTextToken(TextToken tt, TextWriter output)
        {
            var count = 0;

            using (_theme.Apply(output, KonsoleThemeStyle.Text, ref count, _concurrentWriter))
                output.Write(tt.Text);
            return(count);
        }
Ejemplo n.º 2
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            var _ = 0;

            using (_theme.Apply(output, KonsoleThemeStyle.TertiaryText, ref _, _concurrentWriter))
                output.Write(_text);
        }
Ejemplo n.º 3
0
        int RenderValue(KonsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format)
        {
            if (_isLiteral && propertyValue is ScalarValue sv && sv.Value is string)
            {
                var count = 0;
                using (theme.Apply(output, KonsoleThemeStyle.String, ref count, _concurrentWriter))
                    output.Write(sv.Value);
                return(count);
            }

            return(valueFormatter.Format(propertyValue, output, format, _isLiteral));
        }
Ejemplo n.º 4
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            var moniker = LevelOutputFormat.GetLevelMoniker(logEvent.Level, _levelToken.Format);

            if (!Levels.TryGetValue(logEvent.Level, out var levelStyle))
            {
                levelStyle = KonsoleThemeStyle.Invalid;
            }

            var _ = 0;

            using (_theme.Apply(output, levelStyle, ref _, _concurrentWriter))
                Padding.Apply(output, moniker, _levelToken.Alignment);
        }
Ejemplo n.º 5
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            // Padding is never applied by this renderer.

            if (logEvent.Exception == null)
            {
                return;
            }

            var    lines = new StringReader(logEvent.Exception.ToString());
            string nextLine;

            while ((nextLine = lines.ReadLine()) != null)
            {
                var style = nextLine.StartsWith(StackFrameLinePrefix) ? KonsoleThemeStyle.SecondaryText : KonsoleThemeStyle.Text;
                var _     = 0;
                using (_theme.Apply(output, style, ref _, _concurrentWriter))
                    output.WriteLine(nextLine);
            }
        }
Ejemplo n.º 6
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            // If a property is missing, don't render anything (message templates render the raw token here).
            if (!logEvent.Properties.TryGetValue(_token.PropertyName, out var propertyValue))
            {
                Padding.Apply(output, string.Empty, _token.Alignment);
                return;
            }

            var _ = 0;

            using (_theme.Apply(output, KonsoleThemeStyle.SecondaryText, ref _, _concurrentWriter))
            {
                var writer = _token.Alignment.HasValue ? new StringWriter() : output;

                // If the value is a scalar string, support some additional formats: 'u' for uppercase
                // and 'w' for lowercase.
                if (propertyValue is ScalarValue sv && sv.Value is string literalString)
                {
                    var cased = Casing.Format(literalString, _token.Format);
                    writer.Write(cased);
                }
Ejemplo n.º 7
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            // We need access to ScalarValue.Render() to avoid this alloc; just ensures
            // that custom format providers are supported properly.
            var sv = new ScalarValue(logEvent.Timestamp);

            var _ = 0;

            using (_theme.Apply(output, KonsoleThemeStyle.SecondaryText, ref _, _concurrentWriter))
            {
                if (_token.Alignment == null)
                {
                    sv.Render(output, _token.Format, _formatProvider);
                }
                else
                {
                    var buffer = new StringWriter();
                    sv.Render(buffer, _token.Format, _formatProvider);
                    var str = buffer.ToString();
                    Padding.Apply(output, str, _token.Alignment);
                }
            }
        }
Ejemplo n.º 8
0
 protected StyleReset ApplyStyle(TextWriter output, KonsoleThemeStyle style, ref int invisibleCharacterCount)
 {
     return(_theme.Apply(output, style, ref invisibleCharacterCount, _concurrentWriter));
 }