int RenderTextToken(TextToken tt, TextWriter output)
        {
            var count = 0;

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

            using (_theme.Apply(output, ConsoleThemeStyle.TertiaryText, ref _))
                output.Write(_text);
        }
        int RenderValue(ConsoleTheme 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, ConsoleThemeStyle.String, ref count))
                    output.Write(sv.Value);
                return(count);
            }

            return(valueFormatter.Format(propertyValue, output, format, _isLiteral));
        }
Пример #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 = ConsoleThemeStyle.Invalid;
            }

            var _ = 0;

            using (_theme.Apply(output, levelStyle, ref _))
                Padding.Apply(output, moniker, _levelToken.Alignment);
        }
Пример #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) ? ConsoleThemeStyle.SecondaryText : ConsoleThemeStyle.Text;
                var _     = 0;
                using (_theme.Apply(output, style, ref _))
                    output.WriteLine(nextLine);
            }
        }
Пример #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, ConsoleThemeStyle.SecondaryText, ref _))
            {
                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);
                }
        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, ConsoleThemeStyle.SecondaryText, ref _))
            {
                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);
                }
            }
        }
 protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref int invisibleCharacterCount)
 {
     return _theme.Apply(output, style, ref invisibleCharacterCount);
 }