【问题标题】:Writing \t, line feed and carriage return to windows event log from a windows service从 Windows 服务写入 \t、换行和回车到 Windows 事件日志
【发布时间】:2020-07-20 16:16:19
【问题描述】:

我有一个内置于 .NET 和 VB.NET 的 Windows 服务。我正在将日志写入 Windows 事件日志,但我无法写入 \t、换行和回车。

我有一个如下字符串:

Dim myMessage As String = "Parameters read: \n\n"
myMessage += "\t\tParamA: " + paramA
myMessage += "\t\tParamB: " + paramB

日志已写入事件日志,但未应用 \t 和 \n。它显示为单行字符串:

"读取的参数:\n\n\t\tParamA: 2\t\tParamB: 4"

我试过用 %t 代替 \t 和用 %n 代替 \n,但还是不行:

Dim myMessage As String = "Parameters read: %n%n"
myMessage += "%t%tParamA: " + paramA
myMessage += "%t%tParamB: " + paramB

要写入事件日志,我会执行以下操作:

System.Diagnostics.EventLog.WriteEntry(myMessage, System.Diagnostics.EventLogEntryType.Information, 1)

有什么想法吗?

【问题讨论】:

    标签: vb.net event-log


    【解决方案1】:

    您应该使用ControlChars 类及其TabCrLfCrLf 属性。它们是 VB.NET 运行时的一部分,特别是因为 VB 不像 C# 那样支持 C 样式的转义序列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2011-11-23
      • 2014-10-29
      • 2014-11-01
      • 1970-01-01
      相关资源
      最近更新 更多