我的自定义事件日志条目使用什么事件 ID?
自定义应用程序在记录到 Windows EventLog 时是否应使用任何有效事件 ID 范围?或者我可以使用我选择的任何事件 ID (1,2,3,4...)。 PS,我正在使用 C#.NET 进行开发。
Is there any ranges of valid event IDs which should be used by custom applications while logging to Windows EventLog? Or I can use any event ID of my choice (1,2,3,4....).
P.S, I am developing in C#.NET.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
EventId 是特定于应用程序的,因此您可以使用您喜欢的任何范围。只需确保记录您所使用的内容和位置,以便确保不会两次使用 id,或者方便调试。
但请记住......
就像亨利·福特说的“你可以拥有任何你想要的颜色,只要它是黑色” - 你也可以使用任何你喜欢的范围,只要该范围在 0 到 65535 的范围内。
EventIds are application specific so you can use whatever ranges you like. Just ensure you document what you have used and where so that you can ensure you don't use an id twice, or to facilitate easier debugging.
But keep in mind...
Like when Henry Ford said "you can have any color you want as long as it's black" - you can also use whatever range you like as long as that range falls inside the range of 0 and 65535.
果然,由作者来定义和跟踪他们使用的事件 ID 及其含义。
这是一个参考: http://msdn.microsoft.com/en-us/ library/e29k5ebc.aspx - 特别有趣的是关于不将带有 IPv6 地址的消息(因为 % 字符)写入事件日志的部分。我打赌你可以使用一个参数来解决这个问题。
Sure enough, it is up to the author to define and track event IDs they use and what they mean.
Here is a reference: http://msdn.microsoft.com/en-us/library/e29k5ebc.aspx - Particularly interesting is the part about not writing messages with IPv6 addresses (because of the % character) to the event log. I bet you can use a parameter to work around that though.
ID 的高位保留用于测试、调试和用于开发的其他标志。可用位为:
0x0000 - 0xffff
请参阅:事件消息结构
应避免使用高位,但如果您创建自定义源,则低位的所有值都可用。如果您使用系统或预先存在的源,您将发生冲突并可能收到错误的消息。消息取自已注册的源消息 DLL 文件。可以使用 SDK 中的消息文件编译器构建自定义消息文件。
The hi bits of the ID are reserved for testing, debug and other flags used for development. The usable bits are:
0x0000 - 0xffff
See: Event Message Structure
The upper bits should be avoided but all values for the bottom bits are available if you create a custom source. If you use a system or pre-existing source you will collide and likely get the wrong message. Messages are taken from the registered sources message DLL file. A custom message file can be built using the message file compiler from the SDK.
Edit1:我测试过,eventID 是 32 位是不正确的。只有 16 位。
eventId 为 Int32,从 -2,147,483,648 到 2,147,483,647
Edit1: I tested that and it is not true that eventID is 32bits. It is only 16 bits.
eventId is Int32, from -2,147,483,648 to 2,147,483,647
但是,如果您像我一样编写大量详细日志,您会发现很难将一堆条目关联在一起,那么我建议每次执行代码时生成一个随机唯一值,这样您就可以识别事件,甚至更好的想法是创建自己的日志和日志。使用此源而不是在应用程序日志中写入所有内容。喜欢
But if you are someone who writes tons of verbose log like me you will find it difficult to relate a bunch of entries together then I would suggest to generate a random unique value every time the code executes with this you can identify the events, even the much better idea would be to create your own log & source to use this instead of writing everything in the Application log.like