【发布时间】:2018-08-19 20:26:14
【问题描述】:
我们正在通过 API 将 IIS 日志文件推送到 DB 以通过 SPLUNK 进行监控,但我们正在发送重复数据,因为我们的 C# 作业每五分钟运行一次,它会发送所有行
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader(filepath);
while ((line = file.ReadLine()) != null)
{
System.Console.WriteLine(line);
counter++;
}
file.Close();
System.Console.WriteLine("There were {0} lines.", counter);
// Suspend the screen.
System.Console.ReadLine();
【问题讨论】:
-
你能解释一下你的问题吗?
-
向数据添加 ID 字段。我建议以日志 XML 格式制作每个条目。 xml 格式不正确,这意味着根目录中有一个元素数组,但它可以轻松读取结果中的字段。在日志文件中使用 Xml 非常普遍,并且非常容易解析。请参阅以下代码项目:codeproject.com/Articles/28752/Use-XML-for-Log-Files
标签: c# filereader