如何在.Net中读取.ETL文件?

4
我该如何在 .Net 中读取 .ETL 文件?我希望能够在列表视图中查看我的 ETL 文件,但是由于它不是 ASCII 码格式,所以无法解析文件内容。
2个回答

3

没关系,我通过各种谷歌搜索找到了答案。这是我所做的:

    //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");

当SO允许我接受答案时(它说我需要等待2天),我会接受这个答案。 - Chris
顺便说一下,它实际上不是CSV格式,更像是XML格式,而且XML更好:D - Chris
1
他在这里基本上所做的就是 tracerpt <yourfile.etl> -o <yourcsv.csv> - Flo

3
您可以使用P/Invoke和WinAPI的OpenTrace和ProcessTrace函数。在C中MSDN提供了一些示例代码。

P/Invoke允许您从.NET代码调用Win32函数。示例将显示您需要调用哪些函数... - fsimonazzi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接