delphi - 如何使用事件源编写 Windows 日志事件

标签 delphi delphi-xe2 delphi-xe

我正在尝试编写 Windows 日志事件。

我读了这个answer , 并尝试使用它但遇到了同样的问题 reported here "The description for Event ID 1 from source PLCHIDSrv cannot be found..."

我正在尝试 this solution但不知道如何在Delphi中实现这段代码

var data = new EventSourceCreationData("yourApp", "Application");
data.MessageResourceFile = pathToYourMessageFile;
EventLog.CreateEventSource(data);

最佳答案

您收到该错误是因为您没有将事件源添加到 Windows 注册表。

检查 MSDN Documentation :

You can use the default Application log without adding an event source to the registry. However, Event Viewer will not be able to map your event identifier codes to message strings unless you register your event source and provide a message file.

同一链接包含一个带有 C++ 代码的示例,可以轻松将其转换为 Delphi。

更新

我刚找到这篇文章 Writing an event logger with Delphi 2010其中显示了如何将事件源添加到注册表并写入事件日志。

关于delphi - 如何使用事件源编写 Windows 日志事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26640327/

相关文章:

delphi - 有没有更简单的方法来定义基于 bool 值的枚举类型?

delphi - TActionMainMenuBar 渐变绘画

.net - 如何将 Unicode 字符串从托管函数传递到非托管函数

android - 使用 Delphi 10 在 Android 上错误地返回空文件列表

delphi - 创建虚拟打印机作为文档管理系统的接口(interface)

delphi - Firemonkey (FMX) 位图和颜色

delphi - GotoXY 实现

mysql - Delphi Rave Report 生成空白页

arrays - Delphi过程数组参数混淆

delphi - 如何将 32 位和 64 位 DCU 编译到单独的目录中?