-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathExamples.QueryParallelWithCount.cs
More file actions
41 lines (34 loc) · 1.81 KB
/
Copy pathExamples.QueryParallelWithCount.cs
File metadata and controls
41 lines (34 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace EventViewerX.Examples {
internal partial class Examples {
public static async Task QueryParallelWithCount() {
var machineNames = new List<string?> { "AD1", "AD2", "AD3" }; // Add your machine names here
var eventIds = new List<int> { 4932, 4933 }; // Add your event IDs here
// Initialize a dictionary to keep track of the number of events per server
var eventCounts = new Dictionary<string, int>();
await foreach (var eventObject in EventLogEngine.ReadChannelsAsync(
["Security"],
machineNames,
new EventFilter { EventIds = eventIds },
new EventLogQueryOptions { MaxConcurrency = 1 })) {
// If the server is not yet in the dictionary, add it with a count of 1
if (!eventCounts.ContainsKey(eventObject.ComputerName)) {
eventCounts[eventObject.ComputerName] = 1;
}
// If the server is already in the dictionary, increment its count
else {
eventCounts[eventObject.ComputerName]++;
}
// Print an update every 2000 events
if (eventCounts[eventObject.ComputerName] % 2000 == 0) {
Console.WriteLine("Server: {0}, Event Count: {1}", eventObject.ComputerName, eventCounts[eventObject.ComputerName]);
}
}
// Print the final number of events per server
foreach (var pair in eventCounts) {
Console.WriteLine("Server: {0}, Final Event Count: {1}", pair.Key, pair.Value);
}
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}