-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathExamples.CustomProviders.cs
More file actions
72 lines (61 loc) · 2.4 KB
/
Copy pathExamples.CustomProviders.cs
File metadata and controls
72 lines (61 loc) · 2.4 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using EventViewerX.Providers;
namespace EventViewerX.Examples;
internal partial class Examples {
public sealed class ScanCompletedPayload {
[EventProviderPayloadField(0)]
public string ComputerName { get; init; } = string.Empty;
[EventProviderPayloadField(1)]
public uint FindingCount { get; init; }
}
public static EventProviderDefinition CreateCustomProviderDefinition(
string packageVersion = "1.0.0") {
var provider = EventProviderDefinition.Create(
"Contoso.Scanner",
Guid.Parse("7a87f315-4b5e-40a2-b748-b0cdd8adab41"),
packageVersion)
.AddChannel(EventProviderChannelDefinition.Operational(
"Operational",
"Contoso.Scanner/Operational"));
EventProviderEventDefinition scanCompleted =
EventProviderEventDefinition.FromType<ScanCompletedPayload>(
"ScanCompleted",
1000,
"Operational");
scanCompleted.Messages["en-US"] =
"Scan of {ComputerName} found {FindingCount} issues.";
provider.AddEvent(scanCompleted);
return provider;
}
public static EventProviderPackageBuildResult BuildCustomProvider(
string outputPath,
string baselinePath = "") {
return EventProviderPackageBuilder.Build(
CreateCustomProviderDefinition(),
outputPath,
new EventProviderPackageBuildOptions {
BaselinePath = baselinePath,
Overwrite = true
});
}
public static EventProviderPackageInstallResult InstallCustomProvider(
string packagePath,
string trustedSignerThumbprint) {
return EventProviderPackageManager.Install(
packagePath,
new EventProviderPackageInstallOptions {
TrustMode =
EventProviderPackageTrustMode.RequireTrustedSignature,
TrustedSignerThumbprints =
new[] { trustedSignerThumbprint }
});
}
public static ManifestEventWriteResult WriteCustomProviderEvent() {
using var writer = ResolvedManifestEventWriter.Open(
"Contoso.Scanner",
"ScanCompleted");
return writer.Write(new ScanCompletedPayload {
ComputerName = Environment.MachineName,
FindingCount = 7
});
}
}