【问题标题】:Why does ETW EventWriteString have binary payload为什么 ETW EventWriteString 具有二进制有效负载
【发布时间】:2016-01-22 22:48:09
【问题描述】:

我想通过一个我只想记录字符串的附加组件来扩展我的 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是自动设置的。)

【问题讨论】:

    标签: c++ windows logging etw


    【解决方案1】:

    发现添加 id 为 0 的事件和单个字符串输出将在“Microsoft 消息分析器”中显示字符串。

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

    <?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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多