How can I write XML data into the Windows Event Log?
I have noticed that there is a way to insert XML into the windows event log (and not by just stuffing it into the description). The effect is that you get just your description message in the General
view on Windows Vista. You can see your XML data in the Details
view.
If you select the Friendly
radio button, it appears under the Event Data
node. If you select the XML view, then you get to see the XML.
I thought that the rawData byte array in the EventLog.WriteEntry()
method would allow me to do this. I tried stuffing the output of XMLWriter into it. That put data into the event log, but it is viewed as binary instead of XML.
For .Net 4.5 Look into the new EventSource, it also supports generating the manifest automatically.
Unless I am mistaken, in order to write xml to the Crimson/Vista event log you will have create and register a manifest that will give you the appropriate channels and events. Then you have to compile the manifest using the Message Compiler (mc.exe) in the WindowsSDK.
Then if you want to log from C# you will want to create a managed provider to wrap the event logging API. This is a little harder because you will have to use PInvoke to get at the API.
There are blog posts on how to do this whole process here.
You have a sample in Windows SDK (ver 6.1) called EventProvider.
Its a C# provider (needs Vista and up to work) that uses the new Event log API (AKA crimson).
This sample show how to add custom data (amount other things).