本文介绍了EventLog.WriteEntry和EventLog.WriteEvent方法之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用 WriteEntry WriteEvent 事件日志类。

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?

如果只有微小的差别,为什么却没有经过任何 WriteEvent() WriteEntry()方法,而不是引入新的方法,?

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?

推荐答案

EventLog.WriteEntry 是一个快速和肮脏的方式来写的事件日志,你可以写一个字符串。 EventLog.WriteEvent ,您可以利用本地的Win32 API的优势。然而,要做到这一点你应该建立一个本地化的消息文件,你然后编译使用的。每个事件可包含替换字符串,并且可以将其定位于与笔记本计算机上的区域设置。

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.

要避免创建一个消息文件。净包装,它只需插入作为参数提供的字符串事件日志API的使用信息这个额外的步骤。这些消息是由 EventLog.WriteEntry 使用,并在 EventLogMessages.dll 的净文件夹中嵌入的资源存储。

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.

通常情况下使用 EventLog.WriteEntry 是足够的,但如果你需要本地化的信息或希望维持他们的来源$ C ​​$外c您应该创建一个消息文件并使用 EventLog.WriteEvent

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.

这篇关于EventLog.WriteEntry和EventLog.WriteEvent方法之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 13:38