繁体   English   中英

为什么 ETW EventWriteString 具有二进制负载

[英]Why does ETW EventWriteString have binary payload

我想通过一个我只想记录字符串的附加组件来扩展我的 Eventlog(Windows 事件跟踪)。 我正在使用如下代码。

#include <Evntprov.h>
#include <evntrace.h>
#include <minwindef.h>

// {38F4122A-4D8C-465A-9EFC-F7E632A84ABF}
static const GUID MyApplicationGuid = { 0x38f4122a, 0x4d8c, 0x465a, { 0x9e, 0xfc, 0xf7, 0xe6, 0x32, 0xa8, 0x4a, 0xbf } };

REGHANDLE regHandle = nullptr;
EventRegister(MyApplicationGuid, nil, nil, &regHandle);

EventWriteString(regHandle, TRACE_LEVEL_INFORMATION, 0x0, L"Hello");
EventWriteString(regHandle, TRACE_LEVEL_INFORMATION, 0x0, L", ");
EventWriteString(regHandle, TRACE_LEVEL_INFORMATION, 0x0, L"world");
EventWriteString(regHandle, TRACE_LEVEL_INFORMATION, 0x0, L"!");

EventUnregister(regHandle);

我已经注册了一个正确显示的提供程序,这些事件是作为通用事件的 etl 日志文件的一部分。 到目前为止,一切似乎都很好,但是当我想将消息添加为列时,我无法看到记录的字符串,因为它们存储在二进制有效负载元素中。

我有一种方法可以定义事件/模板,以将使用 EventWriteString 完成的跟踪格式化为消息字符串。 像“%1”这样的东西? (标题属性 STRING_ONLY 是自动设置的。)

发现添加 id 为 0 的事件和单个字符串输出将在“Microsoft Messge Analyzer”中显示字符串。

将以下内容添加到您的清单中。

<?xml version="1.0" encoding="UTF-16"?>
<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="COMPANY-PRODUCT-PART" guid="{??????-????-????-????-????????????}" symbol="COMPANY_PRODUCT_PART" resourceFileName="UNKNOWN.dll" messageFileName="UNKNOWN.dll">
        <events>
          <event symbol="DbgStr" value="0" version="0" template="OneStringParamTemplate" message="$(string.Product.1.message)">
          </event>
        </events>
        <templates>
          <template tid="OneStringParamTemplate">
            <data name="param" inType="win:UnicodeString" outType="xs:string">
            </data>
          </template>
        </templates>
      </provider>
    </events>
  </instrumentation>
  <localization>
    <resources culture="en-US">
      <stringTable>
        <string id="Product.1.message" value="%1">
        </string>
      </stringTable>
    </resources>
  </localization>
</instrumentationManifest>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM