コード例 #1
0
 public ThemedMessageTemplateRenderer(HtmlTheme theme, ThemedValueFormatter valueFormatter, bool isLiteral)
 {
     _theme                  = theme ?? throw new ArgumentNullException(nameof(theme));
     _valueFormatter         = valueFormatter;
     _isLiteral              = isLiteral;
     _unthemedValueFormatter = valueFormatter.SwitchTheme(NoTheme);
 }
コード例 #2
0
        public MessageTemplateOutputTokenRenderer(HtmlTheme theme, PropertyToken token)
        {
            _theme = theme ?? throw new ArgumentNullException(nameof(theme));
            _token = token ?? throw new ArgumentNullException(nameof(token));
            bool isLiteral = false, isJson = false;

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

            var valueFormatter = isJson
                ? (ThemedValueFormatter) new ThemedJsonValueFormatter(theme)
                : new ThemedDisplayValueFormatter(theme);

            _renderer = new ThemedMessageTemplateRenderer(theme, valueFormatter, isLiteral);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public OutputFormatter(string outputTemplate)
        {
            if (outputTemplate is null)
            {
                throw new ArgumentNullException(nameof(outputTemplate));
            }
            var template = new MessageTemplateParser().Parse(outputTemplate);

            var theme     = new HtmlTheme();
            var renderers = new List <OutputRenderer>();

            foreach (var token in template.Tokens)
            {
                if (token is TextToken tt)
                {
                    renderers.Add(new TextTokenRenderer(theme, tt.Text));
                    continue;
                }

                var pt = (PropertyToken)token;
                if (pt.PropertyName == OutputProperties.LevelPropertyName)
                {
                    renderers.Add(new LevelTokenRenderer(theme, pt));
                }
                else if (pt.PropertyName == OutputProperties.NewLinePropertyName)
                {
                    renderers.Add(new NewLineTokenRenderer(pt.Alignment));
                }
                else if (pt.PropertyName == OutputProperties.ExceptionPropertyName)
                {
                    renderers.Add(new ExceptionTokenRenderer(theme, pt));
                }
                else if (pt.PropertyName == OutputProperties.MessagePropertyName)
                {
                    renderers.Add(new MessageTemplateOutputTokenRenderer(theme, pt));
                }
                else if (pt.PropertyName == OutputProperties.TimestampPropertyName)
                {
                    renderers.Add(new TimestampTokenRenderer(theme, pt));
                }
                else if (pt.PropertyName == "Properties")
                {
                    renderers.Add(new PropertiesTokenRenderer(theme, pt, template));
                }
                else
                {
                    renderers.Add(new EventPropertyTokenRenderer(theme, pt));
                }
            }

            _renderers = renderers.ToArray();
        }
コード例 #5
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);
        }
コード例 #6
0
 public LevelTokenRenderer(HtmlTheme theme, PropertyToken levelToken)
 {
     _theme      = theme;
     _levelToken = levelToken;
 }
コード例 #7
0
 public ExceptionTokenRenderer(HtmlTheme theme, PropertyToken pt)
 {
     _theme = theme;
 }
コード例 #8
0
ファイル: StyleReset.cs プロジェクト: Daoting/dt
 public StyleReset(HtmlTheme theme, TextWriter output, HtmlThemeStyle style)
 {
     _theme  = theme;
     _output = output;
     _style  = style;
 }
コード例 #9
0
ファイル: ThemedValueFormatter.cs プロジェクト: Daoting/dt
 public abstract ThemedValueFormatter SwitchTheme(HtmlTheme theme);
コード例 #10
0
ファイル: ThemedValueFormatter.cs プロジェクト: Daoting/dt
 protected ThemedValueFormatter(HtmlTheme theme)
 {
     _theme = theme ?? throw new ArgumentNullException(nameof(theme));
 }
コード例 #11
0
 public TimestampTokenRenderer(HtmlTheme theme, PropertyToken token)
 {
     _theme = theme;
     _token = token;
 }
コード例 #12
0
 public override ThemedValueFormatter SwitchTheme(HtmlTheme theme)
 {
     return(new ThemedDisplayValueFormatter(theme));
 }
コード例 #13
0
 public ThemedDisplayValueFormatter(HtmlTheme theme)
     : base(theme)
 {
 }
コード例 #14
0
 public EventPropertyTokenRenderer(HtmlTheme theme, PropertyToken token)
 {
     _theme = theme;
     _token = token;
 }
コード例 #15
0
 public TextTokenRenderer(HtmlTheme theme, string text)
 {
     _theme = theme;
     _text  = text;
 }
コード例 #16
0
 public ThemedJsonValueFormatter(HtmlTheme theme)
     : base(theme)
 {
     _displayFormatter = new ThemedDisplayValueFormatter(theme);
 }