【问题标题】:How to avoid new line in log4net?如何避免 log4net 中的新行?
【发布时间】:2011-11-08 23:44:43
【问题描述】:

每当我尝试使用 log.Error() 打印异常消息时,我都会使用 log4net 进行日志记录。我在日志文件中得到了一个新行。我想避免这种情况。谁能帮帮我。

【问题讨论】:

  • 你能展示用于日志条目和示例条目的模式吗?

标签: log4net


【解决方案1】:

避免这种情况的一种方法是告诉 appender 不要记录堆栈跟踪:

Log4Net - Logging out the Exception stacktrace only for certain files

如果您需要日志文件中的堆栈跟踪,您可以将上述解决方案与一个额外的模式转换器结合使用,该转换器负责编写堆栈跟踪而不创建新行。可以在此处找到示例转换器:

how to convert my decimal thread ID to hex and make it appear in hex format in log4net conversion pattern?

【讨论】:

  • 感谢朋友的评论。但我没有附加堆栈跟踪。我附加了包含 \r\n 的异常消息,log4net 在流的末尾提供了一个额外的 \n ,因此正在打印新行。目前对于所有异常消息,我用空字符串替换 \n 以避免新行是否有任何其他方法可以解决这个问题
猜你喜欢
  • 2020-07-12
  • 1970-01-01
  • 2011-01-05
  • 2020-01-02
  • 1970-01-01
  • 2016-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多