EventLog.WriteEntry 和 EventLog.WriteEvent 方法之间的区别

发布于 2024-09-16 05:31:13 字数 501 浏览 1 评论 0原文

我尝试使用 EventLog 类的 WriteEntryWriteEvent 方法。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-09-23 05:31:13

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 in EventLogMessages.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 use EventLog.WriteEvent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文