public ThemedMessageTemplateRenderer(HtmlTheme theme, ThemedValueFormatter valueFormatter, bool isLiteral)
 {
     _theme                  = theme ?? throw new ArgumentNullException(nameof(theme));
     _valueFormatter         = valueFormatter;
     _isLiteral              = isLiteral;
     _unthemedValueFormatter = valueFormatter.SwitchTheme(NoTheme);
 }
        int RenderValue(HtmlTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format)
        {
            if (_isLiteral && propertyValue is ScalarValue sv && sv.Value is string)
            {
                using (theme.Apply(output, HtmlThemeStyle.String))
                    output.Write(sv.Value);
                return(0);
            }

            return(valueFormatter.Format(propertyValue, output, format, _isLiteral));
        }
示例#3
0
        public PropertiesTokenRenderer(HtmlTheme theme, PropertyToken token, MessageTemplate outputTemplate)
        {
            _outputTemplate = outputTemplate;
            _theme          = theme ?? throw new ArgumentNullException(nameof(theme));
            _token          = token ?? throw new ArgumentNullException(nameof(token));
            var isJson = false;

            if (token.Format != null)
            {
                for (var i = 0; i < token.Format.Length; ++i)
                {
                    if (token.Format[i] == 'j')
                    {
                        isJson = true;
                    }
                }
            }

            _valueFormatter = isJson
                ? (ThemedValueFormatter) new ThemedJsonValueFormatter(theme)
                : new ThemedDisplayValueFormatter(theme);
        }