Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I output "console.write"-style output (no newline) with NLog?

Tags:

c#

.net

nlog

How can I output log as console.write() i.e. no newline with NLog?

${message} defaults to inserting a newline.

like image 445
dfang Avatar asked Nov 04 '22 23:11

dfang


2 Answers

I hope I understand your meaning, it seems that you have new line characters in the string you want to write which causes it to go to the new line in the console, if so replace the newline characters with blank string like below.

string Message = "testMessage\r\n";
Console.Write(Message.Replace("\r\n",""));
like image 63
TBohnen.jnr Avatar answered Nov 09 '22 10:11

TBohnen.jnr


The filetarget has the property LineEnding which could be set to the following values:

  • Default - Insert platform-dependent end-of-line sequence after each line.
  • CR - Insert CR character (ASCII 13) after each line.
  • CRLF - Insert CR LF sequence (ASCII 13, ASCII 10) after each line.
  • LF - Insert LF character (ASCII 10) after each line.
  • None - Don't insert any line ending.

In your case you need None, so:

 <target xsi:type="File"
          name="file1"
          lineEnding="None"

If you need this in another target, e.g. ConsoleTarget, then that isn't implemented. Please open an issue on GitHub.

like image 31
Julian Avatar answered Nov 09 '22 10:11

Julian