c++ - 基于清单的事件不会获取事件数据
问题描述
我正在尝试将事件写入 Windows 事件日志。一切工作正常备用一项:将事件写入事件日志时,我似乎无法在事件日志中显示事件数据。
这是我的清单的副本:
<?xml version="1.0"?>
<instrumentationManifest xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" xmlns="http://schemas.microsoft.com/ win/2004/08/events" xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:trace="http://schemas.microsoft.com/win/2004/08/events/trace">
<instrumentation>
<events>
<provider
name="OperationFilter"
guid="{B7FB08C2-AB1B-448F-BFE0-FB09BEF3659D}"
symbol="OPERATION_FILTER"
resourceFileName="C:\Program Files\TestBindParameters\TestBindParameters.exe"
messageFileName="C:\Program Files\TestBindParameters\TestBindParameters.exe">
<events>
<event
symbol="OPERATION_DB_ERROR"
value="1"
version="0"
channel="Operation-Filter-Admin"
level="win:Error"
message="$(string.OperationFilter.event.1.message)"
template="Operation-Filter-Messages"></event>
</events>
<levels></levels>
<channels>
<channel
name="Operation-Filter-Admin"
chid="Operation-Filter-Admin"
symbol="OPERATION_FILTER_ADMIN"
type="Admin"
enabled="true"></channel>
</channels>
<templates>
<template tid="Operation-Filter-Messages">
<data name="ErrorMessage" inType="win:UnicodeString"></data>
</template>
</templates>
</provider>
</events>
</instrumentation>
<localization>
<resources culture="en-US">
<stringTable>
<string id="level.Error" value="Error"></string>
<string id="OperationFilter.event.1.message" value="There was an error interacting with the database during an operation."></string>
</stringTable>
</resources>
</localization>
</instrumentationManifest>
这是负责写入事件日志的函数:
DWORD writeToEventLog(LPWSTR message)
{
DWORD status = ERROR_SUCCESS;
REGHANDLE RegistrationHandle = NULL;
EVENT_DATA_DESCRIPTOR Descriptors[1];
status = EventRegister(
&OPERATION_FILTER,
NULL,
NULL,
&RegistrationHandle
);
std::wcout << L"message: " << message << std::endl;
if (status != ERROR_SUCCESS)
{
return status;
}
EventDataDescCreate(
&Descriptors[0],
message, //<----this won't show up even though I add it here
sizeof(wchar_t) * (wcslen(message) + 1)
);
status = EventWrite(
RegistrationHandle,
&OPERATION_DB_ERROR,
1,
&Descriptors[0]
);
if (status != ERROR_SUCCESS)
{
std::wcout << L"Unable to write to event log" << std::endl;
}
EventUnregister(RegistrationHandle);
return status;
}
我已对要存储的事件数据发表评论。每当我调用上述方法时,实际上我都会将一个事件写入 Windows 日志,但事件数据为空。当我在 windows 事件日志中查看这些事件时,传递给函数的消息字符串不会出现在事件数据下。我在这里想念什么?
我在此处在线引用了以下示例。我只是错过了一些完全明显的东西吗?
解决方案
所以我在这里回答了我自己的问题。我忘了将我的文件实际复制到适当的位置。如果您要这样做,您必须确定您已将文件正确复制到 resourceFileName 和 messageFileName 位置。否则,您将从事件查看器中获得意外行为。
推荐阅读
- tinymce - 如何在版本 5 的 tinymce 中集成 elFinder?
- sql - Oracle SQL:如何返回几个不同的列
- c++ - 为什么 C++ 隐式类型转换适用于结构但在其他方面适用于类
- firebase - Vuex 中的 Firestore 数据未更改
- dart - 当我更新 mobX 状态并使用观察者更新视图时抛出“MobXException”
- timestamp - 添加带有数字变量的时间戳时的结果是什么?
- javascript - 如何添加作为模板文字一部分的按钮的 onclick 函数?
- javascript - 修改嵌套状态更新失败
- r - 如何基于多列和条件进行模糊连接?
- javascript - 字符限制以“负”数字显示剩余字符