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

标签 .net .net-2.0

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

EventLog.WriteEntry("Saravanan", "Application logs an entry", 
                     EventLogEntryType.Information, 2, 3);
EventLog.WriteEvent("Saravanan",  new EventInstance(2, 3), 
                                 "Application logs an event");

两者输出相同的结果。

这些方法的用法有什么区别吗?

如果只有细微差别,为什么不通过重载 WriteEvent() 来完成?或 WriteEntry()方法,而不是引入新方法?

最佳答案

EventLog.WriteEntry是一种写入事件日志的“快速而肮脏”的方式,您可以在其中写入字符串。 EventLog.WriteEvent使您能够充分利用 native Win32 API。但是,要做到这一点,您应该创建一个本地化的消息文件,然后使用 message compiler (mc.exe) 进行编译。 .每个事件都可以包含替换字符串,并且可以进行本地化以匹配计算机上的区域设置。

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

通常使用 EventLog.WriteEntry足够了,但是如果您需要本地化您的消息或想要在源代码之外维护它们,您应该创建一个消息文件并使用 EventLog.WriteEvent .

关于.net - EventLog.WriteEntry 和 EventLog.WriteEvent 方法之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3599762/

相关文章:

c# - 将 Access 数据导入 SQL Server CE(.mdb 到 .sdf)

.net - .NET Framework可以在Win98上使用吗?

c# - 组合多个谓词

.net - "Could not load file or assembly"使用团队城市构建时

c# - 甲骨文错误 : Pooled connection request timed out

c# - 如何在 C# 中判断 GPS 形状是否相交?

asp.net - 从非 Web 客户端调用 ASP.NET 2.0 身份验证服务

c# - .Net & C# : Trying to have a transparent image on a button (assigned from IDE)

c# - string.format 序列能否以任意顺序出现

.net - 你如何 'cancel' 一个 UdpClient::BeginReceive?