如果你只想一个简单的<代码><Data name=“param1”>data</Data>架构,但如果你想要一个更加复杂的有效载荷,例如像你那样,就会下降:
<Data Name="BugcheckCode">4522044</Data>
<Data Name="BugcheckParameter1">0x74006e00650076</Data>
<Data Name="BugcheckParameter2">0x61007400610044</Data>
<Data Name="BugcheckParameter3">0x610044003c003e</Data>
<Data Name="BugcheckParameter4">0x4e002000610074</Data>
<Data Name="SleepInProgress">7143521</Data>
<Data Name="PowerButtonTimestamp">18577494495789157</Data>
<Data Name="BootAppStatus">6750325</Data>
<Data Name="Checkpoint">99</Data>
<Data Name="ConnectedStandbyInProgress">true</Data>
<Data Name="SystemSleepTransitionsToOn">1795187456</Data>
<Data Name="CsEntryScenarioInstanceId">0</Data>
<Data Name="BugcheckInfoFromEFI">true</Data>
我不认为可以使用<代码>。 活动记录仪。 页: 1 ...... 壳牌:
New-WinEvent -ProviderName Microsoft-Windows-Kernel-Power -Id $evtID -Version 5 -Payload "<EventData><Data Name=""BugcheckCode"">210</Data><Data Name=""BugcheckParameter1"">0xffffc080b5744760</Data><Data Name=""BugcheckParameter2"">0x2</Data><Data Name=""BugcheckParameter3"">0x0</Data><Data Name=""BugcheckParameter4"">0xfffff80261641530</Data><Data Name=""SleepInProgress"">0</Data><Data Name=""PowerButtonTimestamp"">0</Data><Data Name=""BootAppStatus"">0</Data><Data Name=""Checkpoint"">0</Data><Data Name=""ConnectedStandbyInProgress"">false</Data><Data Name=""SystemSleepTransitionsToOn"">0</Data><Data Name=""CsEntryScenarioInstanceId"">0</Data><Data Name=""BugcheckInfoFromEFI"">false</Data><Data Name=""CheckpointStatus"">0</Data></EventData>"
因此,我排除了这一用途的代价,并反映了该守则。 我最后用几类助手,使你能够通过你要求的任何有效载荷:
public class EventLogHelper
{
/// <summary>
/// Taken from the source code of Microsoft.PowerShell.Commands.NewWinEventCommand
/// </summary>
/// <param name="providerName">"Microsoft-Windows-Kernel-Power"</param>
/// <param name="eventId">41</param>
/// <param name="version">5</param>
/// <param name="payLoad"></param>
public static void AddEventToEventLog(string providerName, long eventId, int version, string payLoad = "")
{
using (ProviderMetadata providerMetaData = LoadProvider(providerName))
{
EventDescriptor eventDescriptor = LoadEventDescriptor(providerMetaData, eventId, Convert.ToByte(version));
ProcessRecord(providerMetaData, eventDescriptor, payLoad);
}
}
private static ProviderMetadata LoadProvider(string providerName)
{
using (EventLogSession eventLogSession = new EventLogSession())
{
IEnumerable<string> providers = eventLogSession.GetProviderNames().OrderBy(s => s);
foreach (string providerName2 in providers)
{
if (string.Equals(providerName2, providerName, StringComparison.OrdinalIgnoreCase))
{
return new ProviderMetadata(providerName2);
}
}
}
throw new Exception("Failed to find Microsoft-Windows-Kernel-Power provider");
}
private static EventDescriptor LoadEventDescriptor(ProviderMetadata providerMetadata, long id, byte version)
{
EventMetadata eventMetadata = providerMetadata.Events.First(f => f.Id == id && f.Version == version);
return CreateEventDescriptor(providerMetadata, eventMetadata);
}
private static EventDescriptor CreateEventDescriptor(ProviderMetadata providerMetaData, EventMetadata emd)
{
long num = 0L;
foreach (EventKeyword keyword in emd.Keywords)
{
num |= keyword.Value;
}
byte b = 0;
using (IEnumerator<EventLogLink> enumerator2 = providerMetaData.LogLinks.GetEnumerator())
{
while (enumerator2.MoveNext() && !string.Equals(enumerator2.Current.LogName, emd.LogLink.LogName, StringComparison.OrdinalIgnoreCase))
{
b = (byte)(b + 1);
}
}
int parsedId = (int)emd.Id;
if (emd.Id > ushort.MaxValue)
parsedId = (ushort)emd.Id;
return new EventDescriptor(parsedId, emd.Version, b, (byte)emd.Level.Value, (byte)emd.Opcode.Value, emd.Task.Value, num);
}
private static void ProcessRecord(ProviderMetadata providerMetadata, EventDescriptor eventDescriptor, string payload)
{
using (EventProvider eventProvider = new EventProvider(providerMetadata.Id))
{
eventProvider.WriteEvent(ref eventDescriptor, payload);
}
}
}
之后,可以称为:
string payload = @"<EventData><Data Name=""BugcheckCode"">210</Data><Data Name=""BugcheckParameter1"">0xffffc080b5744760</Data><Data Name=""BugcheckParameter2"">0x2</Data><Data Name=""BugcheckParameter3"">0x0</Data><Data Name=""BugcheckParameter4"">0xfffff80261641530</Data><Data Name=""SleepInProgress"">0</Data><Data Name=""PowerButtonTimestamp"">0</Data><Data Name=""BootAppStatus"">0</Data><Data Name=""Checkpoint"">0</Data><Data Name=""ConnectedStandbyInProgress"">false</Data><Data Name=""SystemSleepTransitionsToOn"">0</Data><Data Name=""CsEntryScenarioInstanceId"">0</Data><Data Name=""BugcheckInfoFromEFI"">false</Data><Data Name=""CheckpointStatus"">0</Data></EventData>";
EventLogHelper.AddEventToEventLog("Microsoft-Windows-Kernel-Power", 41, 5, payload);