【发布时间】:2015-01-05 16:36:46
【问题描述】:
对于这个项目,我将输入一个 SQL 数据库并将其放入一个 txt 文件中,以便于传输,而不是什么。
到目前为止它有效,但我想让它更易于阅读。当这个应用程序运行时,它每 60 秒更新一次文件。我想在列中添加标题,以便阅读它的人可以知道每列代表什么。 我不知道如何添加标题,以便每次刷新都添加新文本插入标题下方。
这是我目前所拥有的
private void Output()
{
string createText = "";
foreach (KeyValuePair<string, AlarmData> AlarmDataText in AlarmDictionary)
{
createText += FormatWidth(AlarmDataText.Value.eventSeverity, 8) + FormatWidth(AlarmDataText.Value.eventLastNotification.ToString("yyyy-MM-dd HH:mm"), 18) +
FormatWidth(AlarmDataText.Value.eventFirstNotification.ToString("yyyy-MM-dd HH:mm"), 18) + FormatWidth(AlarmDataText.Value.deviceIP, 18) +
FormatWidth(AlarmDataText.Value.deviceInterface, 20) + AlarmDataText.Value.descriptionShort;
createText += Environment.NewLine;
}
if (true)
{
}
File.WriteAllText("C:\\Users\\%username%\\Documents\\Visual Studio 2010\\Projects\\NMS_Logger\\NMS_Logger\\bin\\Log.txt", createText);
}//end Output()
这是它在文本文件中的输出示例
Major 2015-01-05 11:15 2014-11-11 09:55 10.10.10.1 apSysMgmtInet
Major 2015-01-05 11:15 2014-11-11 09:56 10.10.10.1 apSysMgmtInet
Major 2015-01-05 11:16 2014-11-13 12:35 10.10.10.1 bwCNAMS C N A M Server
Info 2015-01-05 11:17 2015-01-02 03:29 10.10.10.1 CIT Debug Trap
Major 2015-01-05 11:15 2014-11-14 09:48 10.10.10.1 RAI telicaT1Alarm
Major 2015-01-05 11:17 2014-11-20 02:11 10.10.10.1 portErrorsExceeded
Info 2015-01-05 11:15 2015-01-05 11:14 10.10.10.1 NORMAL telicaT1Event
Major 2015-01-05 11:15 2014-11-14 09:48 10.10.10.1 RAI telicaT1Alarm
Info 2015-01-05 11:15 2015-01-05 11:14 10.10.10.1 NORMAL telicaT1Event
Major 2015-01-05 11:17 2014-11-12 05:05 10.10.10.1 Error ENVMON
Info 2015-01-05 11:16 2014-12-03 15:43 10.10.10.1 Debug SEC
如您所见,列标签会很好。
【问题讨论】:
-
您可以使用 SELECT 硬编码列名 UNION ALL。
-
使用
StringBuilder而不是在循环中附加到String- 它要快得多。