EventLog.WriteEntry 和 EventLog.WriteEvent 方法之间的区别
我尝试使用 EventLog
类的 WriteEntry
和 WriteEvent
方法。
EventLog.WriteEntry("Saravanan", "Application logs an entry",
EventLogEntryType.Information, 2, 3);
EventLog.WriteEvent("Saravanan", new EventInstance(2, 3),
"Application logs an event");
两者输出相同的结果。
这些方法的使用有什么区别吗?
如果只有很小的差异,为什么不通过重载 WriteEvent()
或 WriteEntry()
方法来完成,而不是引入新方法?
I tried using WriteEntry
and WriteEvent
methods of EventLog
class.
EventLog.WriteEntry("Saravanan", "Application logs an entry",
EventLogEntryType.Information, 2, 3);
EventLog.WriteEvent("Saravanan", new EventInstance(2, 3),
"Application logs an event");
Both output the same result.
Is there any difference in usage of these methods?
If there are only minor difference, why was it not done through a overload of either WriteEvent()
or WriteEntry()
methods, instead of introducing a new method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EventLog.WriteEntry
是一种“快速而肮脏”的写入事件日志的方法,您可以在其中写入字符串。EventLog.WriteEvent
使您能够充分利用本机 Win32 API。但是,要做到这一点,您应该创建一个本地化消息文件,然后使用 消息编译器 (mc.exe)。每个事件都可以包含替换字符串,并且可以进行本地化以匹配计算机上的区域设置。为了避免创建消息文件这一额外步骤,事件日志 API 的 .Net 包装器使用仅插入作为参数提供的字符串的消息。这些消息由
EventLog.WriteEntry
使用,并作为嵌入资源存储在 .Net 文件夹中的EventLogMessages.dll
中。通常使用
EventLog.WriteEntry
就足够了,但如果您需要本地化消息或希望在源代码之外维护它们,您应该创建一个消息文件并使用EventLog.WriteEvent
。EventLog.WriteEntry
is a "quick and dirty" way to write to the event log where you can write a string.EventLog.WriteEvent
enables you to take full advantage of the native Win32 API. However, to do that you are supposed to create a localized message file you then compile using the message compiler (mc.exe). Each event can contain substitution strings and can be localized to match the locale on the computer.To avoid this extra step of creating a message file the .Net wrapper for the event log API use messages that simply inserts the strings supplied as arguments. These message are used by
EventLog.WriteEntry
and are stored as embedded resources inEventLogMessages.dll
in the .Net folder.Normally using
EventLog.WriteEntry
is adequate, but if you need to localize your messages or want to maintain them outside your source code you should create a message file and useEventLog.WriteEvent
.