Nlog: I want to truncate message layout renderer after 30 characters in database logging.Any suggestion?

Created on 12 Dec 2018  路  5Comments  路  Source: NLog/NLog

Hi! Thanks for reporting this feature/bug/question!

Please keep / fill in the relevant info from this template so that we can help you as best as possible.

QUESTIONS are preferred on StackOverflow. You could expect a faster response there (but do include all the info below). Use the tag "nlog" https://stackoverflow.com/questions/ask

For .NET Core users, please check the platform support: https://github.com/NLog/NLog/wiki/platform-support

NLog version: (e.g. 4.2.3)

Platform: .Net 3.5 / .Net 4.0 / .Net 4.5 / Mono 4 / Silverlight 4 / Silverlight 5 / Xamarin Android / Xamarin iOs / .NET Core 1 / .NET Core 2

Current NLog config (xml or C#, if relevant)

<nlog>
  <targets>
  </targets>
  <rules>
  </rules>
</nlog>

  • Why do we need it?
  • An example of the XML config, if relevant.
question

Most helpful comment

NLog 4.6.3 has been released, that allows you to do this:

${message:truncate=30}

See also https://www.nuget.org/packages/NLog

All 5 comments

This very cryptic logic will truncate the log-message to 30 chars:

${trim-whitespace:inner=${message:padding=-30:fixedLength=true}}

NLog ver. 4.6 will include a ${left} and ${right} wrapper that makes the truncate-config easier.

I assume your question has been answered, if not, please let us know!

NLog 4.6.3 has been released, that allows you to do this:

${message:truncate=30}

See also https://www.nuget.org/packages/NLog

Is there any way I can add ellipsis at the end when message got truncated?
Similar to:

Some pretty long messa...

Please open a new issue, or even better, ask on StackOverflow

Was this page helpful?
0 / 5 - 0 ratings