Putting XML Data into the Windows Event Log

2019-01-20 02:53发布

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.

3条回答
对你真心纯属浪费
2楼-- · 2019-01-20 02:55

For .Net 4.5 Look into the new EventSource, it also supports generating the manifest automatically.

查看更多
放荡不羁爱自由
3楼-- · 2019-01-20 02:59

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.

查看更多
萌系小妹纸
4楼-- · 2019-01-20 03:20

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).

查看更多
登录 后发表回答