Nlog: How to log fullname of level, like "Information" instead of "Info"

Created on 28 Nov 2019  路  4Comments  路  Source: NLog/NLog

How to log fullname of level, like "Information" instead of "Info". Our current implementation is that we added a Sumologic provider directly to the Microsoft logging extensions. What we see here is that the levels are logged as "Warning" and "Information". We now try to move to Nlog with a SumologicTarget. Everything works except for the level. Nlog abbreviates them to "Warn" and "Info". I tried using ${level:format=Name}, but that still uses the abbreviation. Anyway of accomplishing this without completely needing to write a custom renderer?

question

Most helpful comment

Thanks for reacting so fast. The custom renderer is already working now. But it is impressive to see how fast issues actually lead to solutions. Thanks for the help.

All 4 comments

Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

Think it is a good idea to extend NLog ${level} renderer to show full-name. Though it might not work completely since there is also MEL-Critical (Matches NLog Fatal):

But you can use the dark-magic in NLog to create your own custom layout-renderer:

  <variables>
    <variable name="FullLevel" value="${level:when=level!=LogLevel.Info and level!=LogLevel.Warn and level != LogLevel.Fatal}${when:when=level==LogLevel.Info:inner=Information}${when:when=level==LogLevel.Warn:inner=Warning}${when:when=level==LogLevel.Fatal:inner=Critical}" />
  </variables>
  <targets>
    <target xsi:type="Console" name="consoleTarget" layout="${date}|${FullLevel}|${message}" />
  </targets>

Notice how the NLog-config-variable ${fulllevel} converts from NLog-LogLevel to MEL-LogLevel, and then can be reference in other layouts.

@geedsen Created #3713 that introduces the Format=FullName for ${level}

Thanks for reacting so fast. The custom renderer is already working now. But it is impressive to see how fast issues actually lead to solutions. Thanks for the help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FaMouZx3 picture FaMouZx3  路  3Comments

Rapiiidooo picture Rapiiidooo  路  3Comments

vasumsit picture vasumsit  路  3Comments

geedsen picture geedsen  路  3Comments

Jerefeny picture Jerefeny  路  3Comments