Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

c# - Putting XML Data into the Windows Event Log

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...