Click here to Skip to main content
15,346,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

current i am looking for a way to write multiple data tags to an event log entry, i can write an entry to the event log with no issues however i want to be able to input multiple tags like you can see in the XML view of event viewer:

<EventData>
    <Data Name="MyValue1">ABCDEFG</Data>
    <Data Name="MyValue2">HIJKLMN</Data>
    <Data Name="MyValue3">OPQRSTU</Data>
</EventData>


I Currently use the below to write to the event log but could really do with giving more parameters on this to allow filtering on the event log.
VB
evtLog.WriteEntry("My Message", EventLogEntryType.Information)


Regards
Dave
Posted

Neither of these are exactly how you describe, but may fit your requirements.

Firstly this article Enhanced EventLog writing for .NET Applications[^].

Or a simple alternative could be something like this
C#
var sb = new StringBuilder("");
sb.Append(new XElement("MyValue1", "ABCDEFG").ToString());
sb.Append(new XElement("MyValue2", "HIJKLMN").ToString());
sb.Append(new XElement("MyValue3", "OPQRSTU").ToString());

EventLog.WriteEntry("MyProgram", sb.ToString(), EventLogEntryType.Information);

which gave
XML
<EventData>
   <Data><MyValue1>ABCDEFG</MyValue1><MyValue2>
       HIJKLMN</MyValue2><MyValue3>OPQRSTU</
       MyValue3></Data>
</EventData>

Note the Data is provided by the EventViewer
   
Comments
Dev O'Connor 17-Jun-15 15:41pm
   
Thanks for the response, I am currently already inputting the data in to event viewer with the above method, but when i am trying to create a custom view and using XML filtering you cannot filter down on an XML element as you cant use wildcards so i cannot find data within it so i cant fine "HIJ" within an XML element.

DO you have any other thoughts.
Dev O'Connor 17-Jun-15 17:03pm
   
So i have managed to get the multiple data tags by creating it using EventEntry

EventLog.WriteEvent("MySource", New EventInstance(0, 0, EventLogEntryType.Error), {1, 2, 3, 4, 5})

Just trying to get the Name attribute inside the data tag now, any thoughts>
Dev O'Connor 17-Jun-15 17:07pm
   
So i have managed to get the multiple data tags by creating it using EventEntry

<pre lang="vb">EventLog.WriteEvent("MySource", New EventInstance(0, 0, EventLogEntryType.Error), {1, 2, 3, 4, 5})</pre>

Do you know how to give the Tags names now as

<pre lang="text">
<eventdata>
1
2
3
4
5

CHill60 18-Jun-15 5:58am
   
Sorry I don't. Might be worth raising a new question (make sure the title is different or people will think it's a repost.
Dev O'Connor 18-Jun-15 6:00am
   
Thanks, will do :)
Dev O'Connor 18-Jun-15 6:07am
   
http://www.codeproject.com/Questions/1002110/EventLog-WriteEvent-Add-Data-Name-Attribute-to-Eve
To output data tags:

VB
EventLog.WriteEvent("MySource", New EventInstance(0, 0, EventLogEntryType.Error), {1, 2, 3, 4, 5})
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900