如何使用c#</eventdata>在事件查看器<eventdata>中为数据条目添加名称

时间:2014-01-30 05:27:22

标签: c# event-viewer

要求将多个数据项写入事件查看器<eventData>,如下所示

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> 
   <System> 
       <Provider Name="Elib" /> 
       <EventID Qualifiers="0">0</EventID> 
       <Level>4</Level> 
       <Task>0</Task> 
       <Keywords>0x80000000000000</Keywords> 
       <TimeCreated SystemTime="2014-01-03T12:42:30.000000000Z" /> 
       <EventRecordID>33</EventRecordID> 
       <Channel>Elib</Channel> 
       <Computer>48vtvs1</Computer> 
       <Security /> 
   </System> 
   <EventData> 
       <Data>Entry1</Data> 
       <Data>Entry2</Data> 
   </EventData> 
</Event>

我可以在<eventdata>下使用以下代码

编写多个条目
EventLog.WriteEvent("Application", 
new EventInstance(1001, 0, EventLogEntryType.Information), 
new object[] { "Entry1", "Entry2" });

输出:

<EventData> 
   <Data>Entry1</Data> 
   <Data>Entry2</Data> 
</EventData> 

但我的要求是将名称属性添加到数据节点,如下所示

<EventData> 
<Data name="title">Entry1</Data> 
<Data name=Message">Entry2</Data> 
</EventData> 

0 个答案:

没有答案