question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

String arguments are not colorized when using a custom ExpressionTemplate

See original GitHub issue

I noticed that when using a custom ExpressionTemplate, my placeholders in log messages are no longer colorized. Is this a bug? e.g. Log.Information("foo {bar}", "bar") won’t color the "bar" anymore.

I suspect it’s only a problem with string arguments.

My template:

var template = new ExpressionTemplate(
                "[{@l:u3}] {Coalesce(Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1),'Core')} " +
                "<{ThreadId}> {@m}\n{@x}", theme: TemplateTheme.Code);

Without ExpressionTemplate:

image

With ExpressionTemplate:

image

I’m not sure if this a problem in expressions, or in the console sink.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Meligycommented, Sep 19, 2022

Actually, removing all formatting strings seems to work. Thanks.

0reactions
rcdaileycommented, Dec 10, 2022

I added my thumbs up to this issue, although I’m not sure if votes are effective here.

I will say there are two major issues I ran into that made migration from the default template system to this one challenging:

  1. It wasn’t clear to me at first that the existing template syntax wasn’t compatible with this new Serilog.Expressions system. I thought the basic elements (like message, level, etc) would work out of the box.
  2. The coloring issue was weird and eventually lead me to this issue.

I think number 1 can be solved with documentation (or if it already exists, I somehow missed it). Number 2 as stated here seems to be broken by using formatters (and as part of the first point, it not being clear that some of them aren’t needed, as was the case for @m:lj).

I appreciate the workaround from @nblumhardt!

Read more comments on GitHub >

github_iconTop Results From Across the Web

serilog/serilog-expressions
An embeddable mini-language for filtering, enriching, and formatting Serilog events, ideal for use with JSON or XML configuration.
Read more >
Is it possible to change colors in serilog?
Yes, the way to change colors when using the Console sink is through themes. You can try one of the built-in ones, or...
Read more >
Customizing Serilog text output
The Coalesce() function accepts a variable number of arguments, and will return the first of them that is not null or undefined.
Read more >
Compound Discoverer 3.1 – User Guide (Revision A)
Setting Up a New Study and a New Analysis by Using the Wizard . ... Changing the Hierarchy of the Study Variables ....
Read more >
Compound Discoverer 3.0 – User Guide (Revision A)
Creating, Deleting, Importing, or Exporting a Custom Color Palette . . . . . 451 ... using the following user-specified parameter settings:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found