我该如何在 .Net 中读取 .ETL 文件?我希望能够在列表视图中查看我的 ETL 文件,但是由于它不是 ASCII 码格式,所以无法解析文件内容。
没关系,我通过各种谷歌搜索找到了答案。这是我所做的:
//Init
System.Diagnostics.Process worker = new System.Diagnostics.Process();
//Start logging
worker.StartInfo.FileName="logman";
worker.StartInfo.Arguments="start MyTcpipLog -p Microsoft-Windows-TCPIP -ets";
worker.Start();
worker.WaitForExit();
//Do nothing for 30 seconds
DateTime start = DateTime.Now;
while(DateTime.Now.Subtract(start).Seconds<5){}
//Stop logging
worker.StartInfo.FileName="logman";
worker.StartInfo.Arguments="stop MyTcpipLog -ets";
worker.Start();
worker.WaitForExit();
//Convert .etl to .csv
worker.StartInfo.FileName="tracerpt";
worker.StartInfo.Arguments = "\""+System.IO.Path.GetDirectoryName(Application.ExecutablePath)+"\\MyTcpipLog.etl\" -o \""+System.IO.Path.GetDirectoryName(Application.ExecutablePath)+"\\MyTcpipLog.csv\"";
worker.Start();
worker.WaitForExit();
//Load CSV into memory
// create reader & open file
System.IO.TextReader tr = new System.IO.StreamReader("MyTcpipLog.csv");
string data = tr.ReadToEnd();
tr.Close();
//Delete CSV
System.IO.File.Delete("MyTcpipLog.etl");
System.IO.File.Delete("MyTcpipLog.csv");
tracerpt <yourfile.etl> -o <yourcsv.csv>
。 - Flo