1

I'm aware that when logging with serilog, log level names (Verbose, Debug, Information, Warning etc) can either be left with their full name, or truncated to an either upper or lowercase representation by doing something similar to {Level:u3} - but how can I completely change the level names?

For example, I may want the level names to be in a different language to match the rest of my application.

Or, in my particular case, I find that the level "full names" are too big, but that having all level names with a specific length makes it much harder to identify messages of a different level when quickly scrolling through a log.

So I'd like to instead have:

  • VERBOSE
  • DBG
  • INFO
  • WARNING
  • *EXCEPTION*
  • **FATAL**

But I'm not sure how to accomplish this. How can this be achieved in serilog?

Asterisk
  • 11
  • 2
  • 1
    Does this answer your question? [How do I modify Serilog Log Levels to match up with Log4Net?](https://stackoverflow.com/questions/51629436/how-do-i-modify-serilog-log-levels-to-match-up-with-log4net) – C. Augusto Proiete Dec 17 '20 at 20:13

2 Answers2

1

You can use a custom formatter with Serilog and there write the messages with their levels as you wish.

https://github.com/serilog/serilog/wiki/Formatting-Output

The ITextFormatter may be better for what you need:
https://stackify.com/serilog-tutorial-net-logging/

Idov
  • 5,006
  • 17
  • 69
  • 106
1

You make an Enricher to map the level to the string you want, then you reference the field it adds in the outputTemplate

However, you're better off using the :u3 or another stable length rendering (or do something like {LogLevel,10:u} to make the column fixed width)

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249