public ThemedMessageTemplateRenderer(HtmlTheme theme, ThemedValueFormatter valueFormatter, bool isLiteral) { _theme = theme ?? throw new ArgumentNullException(nameof(theme)); _valueFormatter = valueFormatter; _isLiteral = isLiteral; _unthemedValueFormatter = valueFormatter.SwitchTheme(NoTheme); }
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); }
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)); }
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(); }
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); }
public LevelTokenRenderer(HtmlTheme theme, PropertyToken levelToken) { _theme = theme; _levelToken = levelToken; }
public ExceptionTokenRenderer(HtmlTheme theme, PropertyToken pt) { _theme = theme; }
public StyleReset(HtmlTheme theme, TextWriter output, HtmlThemeStyle style) { _theme = theme; _output = output; _style = style; }
public abstract ThemedValueFormatter SwitchTheme(HtmlTheme theme);
protected ThemedValueFormatter(HtmlTheme theme) { _theme = theme ?? throw new ArgumentNullException(nameof(theme)); }
public TimestampTokenRenderer(HtmlTheme theme, PropertyToken token) { _theme = theme; _token = token; }
public override ThemedValueFormatter SwitchTheme(HtmlTheme theme) { return(new ThemedDisplayValueFormatter(theme)); }
public ThemedDisplayValueFormatter(HtmlTheme theme) : base(theme) { }
public EventPropertyTokenRenderer(HtmlTheme theme, PropertyToken token) { _theme = theme; _token = token; }
public TextTokenRenderer(HtmlTheme theme, string text) { _theme = theme; _text = text; }
public ThemedJsonValueFormatter(HtmlTheme theme) : base(theme) { _displayFormatter = new ThemedDisplayValueFormatter(theme); }