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

一世执手 提交于 2019-12-23 11:47:10

问题


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

${message} defaults to inserting a newline.


回答1:


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",""));



回答2:


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.




回答3:


To log items in the console, use console.log(item).




回答4:


It seems there is a property named LineEndingMode / LineEnding, which you could try to modify.



来源:https://stackoverflow.com/questions/5699294/how-can-i-output-console-write-style-output-no-newline-with-nlog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!