我想獲取C#中的「特殊」事件日誌列表,如「Microsoft \ Windows \ Audio \ CaptureMonitor」日誌和所有其他喜歡它的列表。當我使用System.Diagnostics.EventLog.GetEventLogs()時,它們似乎不會被返回。有沒有特殊的方法來獲取所有特殊事件日誌的列表?在C中枚舉特殊事件日誌#
1
A
回答
1
我會誠實地承認,我不知道這些觀點是如何綁定到事件日誌時和EventSources但看一看註冊表項:
HKLM \ SOFTWARE \微軟\的Windows \ CurrentVersion \ WINEVT \頻道
然後看看是否讓你走上正確的道路。此外結帳:
How do I create a hierarchy of lognames in the Windows event system?
0
您可以使用WevtUtil.exe tool:
訪問事件的命令行日誌信息,使用 WevtUtil.exe工具。該工具位於%SystemRoot%\ System32 目錄中。對於WevtUtil.exe工具幫助,請使用wevtutil /?命令。
我想你可能會使用System.Diagnostigs.Process
,啓動該工具,然後捕獲並解析控制檯輸出。
using System;
using System.Diagnostics;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var output = "";
var p = new Process();
var psi = new ProcessStartInfo("wevtutil.exe", "el");
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
p.StartInfo = psi;
p.Start();
using (var processOutput = p.StandardOutput)
{
output = processOutput.ReadToEnd();
}
p.WaitForExit();
var eventLogs = output
.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
foreach (var item in eventLogs)
{
Console.WriteLine(item);
}
}
}
對於閱讀事件日誌,你可以使用相同的方法(例如,呼叫wevtutil qe Microsoft-Windows-Audio/CaptureMonitor /f:text
)或System.Diagnostics.Eventing.Reader
Namespace。嘗試以下操作:
using System;
using System.Diagnostics.Eventing.Reader;
class Program
{
static void Main(string[] args)
{
EventLogQuery subscriptionQuery =
new EventLogQuery("Microsoft-Windows-Audio/CaptureMonitor",
PathType.LogName, "*");
using (EventLogReader logReader =
new EventLogReader(subscriptionQuery))
{
DisplayEventAndLogInformation(logReader);
}
}
private static void DisplayEventAndLogInformation(EventLogReader logReader)
{
for (EventRecord eventInstance = logReader.ReadEvent();
null != eventInstance; eventInstance = logReader.ReadEvent())
{
Console.WriteLine("--------------------------------------");
Console.WriteLine("Event ID: {0}", eventInstance.Id);
Console.WriteLine("Publisher: {0}", eventInstance.ProviderName);
try
{
Console.WriteLine("Description: {0}",
eventInstance.FormatDescription());
}
catch (EventLogException)
{
// The event description contains parameters,
// and no parameters were passed to the
// FormatDescription method, so an exception is thrown.
}
// Cast the EventRecord object as an EventLogRecord
// object to access the EventLogRecord class properties
EventLogRecord logRecord = (EventLogRecord)eventInstance;
Console.WriteLine("Container Event Log: {0}",
logRecord.ContainerLog);
}
}
}
您可能需要調整一點點EventLogQuery
構造函數的查詢參數(*
)根據您的需要。主題How to: Query for Events顯示了一個實現示例。
相關問題
- 1. C#中事件日誌枚舉器的內存使用情況
- 2. 特殊字符添加日期枚舉
- 3. 標誌,枚舉(C)
- 4. 如何枚舉事件日誌的所有註冊源
- 5. C#枚舉標誌比較
- 6. C#的int標誌枚舉
- 7. 特殊成員枚舉:全部和無
- 8. 地圖枚舉爲[標誌]枚舉
- 9. 在C中閱讀事件日誌#
- 10. 枚舉在C++
- 11. 大標誌枚舉
- 12. java - 如何在枚舉中添加特殊字符?
- 13. 將特殊字符作爲枚舉值存儲在Rails 5中
- 14. 枚舉更改事件
- 15. 枚舉所有IEnumerable事件
- 16. Linux USB枚舉和事件
- 17. C#標誌枚舉分隔符
- 18. C#具有標誌的枚舉屬性
- 19. C#標誌枚舉字大小
- 20. 標誌和<<枚舉操作? C#
- 21. 在枚舉中枚舉
- 22. WPF DataBinding標誌枚舉(在PropertyGrid中)
- 23. 如何在枚舉單例中實現日誌記錄?
- 24. 枚舉頭文件在C++中
- 25. 在C中枚舉文件句柄#
- 26. 在C中傳入枚舉
- 27. 使用枚舉在C#中
- 28. 在C中使用枚舉#
- 29. 訪問本地事件日誌在C#
- 30. 枚舉Outlook加載項中的聯繫人和日曆事件?
我知道如何閱讀的特殊事件日誌,我試圖讓所有的特殊事件日誌列表。我瀏覽過EventLog *類,到目前爲止還沒有提供任何有用的東西。 :( – 2013-03-14 19:10:16