2011-05-28 61 views

回答

2

沒關係,我使用各種谷歌搜索計算出來。我這是怎麼做的:

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

將接受這個作爲我的答案,當SO讓我(說我需要等待2天) – Chris 2011-05-28 23:40:30

+0

順便說一句,其實不是csv,看起來更像xml,這更好:D – Chris 2011-05-28 23:41:59

2

您可能可以使用P/Invoke和WinAPI OpenTrace和ProcessTrace函數。 See MSDN對於C中的一些示例代碼。

+0

一直在尋找C#.NET不是C ^^但我還是謝謝你我猜 – Chris 2011-05-28 23:42:55

+0

的P/Invoke允許您從.NET代碼中調用Win32函數。樣本會顯示你需要調用哪些功能... – fsimonazzi 2012-10-17 19:59:50