如何在Microsoft.Diagnostics.Tracing.EventSource中正确定义关键字? [英] How to properly define Keywords in Microsoft.Diagnostics.Tracing.EventSource?

查看:510
本文介绍了如何在Microsoft.Diagnostics.Tracing.EventSource中正确定义关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Microsoft.Diagnostics.Tracing.EventSource nuget包将事件写入事件日志.在我的自定义类中定义关键字时,该关键字继承自 EventSource 像这样:

I am using the Microsoft.Diagnostics.Tracing.EventSource nuget package to write events to the eventlog. When defining keywords in my custom class inheriting from EventSource like this:

public class Keywords
{
    public const EventKeywords Page = ( EventKeywords ) 0x1;
    public const EventKeywords DataBase = ( EventKeywords ) 0x2;
    public const EventKeywords Diagnostic = ( EventKeywords ) 0x4;
    public const EventKeywords Perf = ( EventKeywords ) 0x8;
}

我得到一个包含以下xml的清单文件:

I get a manifest file containing the following xml:

<keywords>
    <keyword name="DataBase" message="$(string.keyword_DataBase)" mask="0x1"/>
    <keyword name="Page" message="$(string.keyword_Page)" mask="0x2"/>
    <keyword name="Diagnostic" message="$(string.keyword_Diagnostic)" mask="0x4"/>
    <keyword name="Perf" message="$(string.keyword_Perf)" mask="0x8"/>
    <keyword name="Session3" message="$(string.keyword_Session3)" mask="0x100000000000"/>
    <keyword name="Session2" message="$(string.keyword_Session2)" mask="0x200000000000"/>
    <keyword name="Session1" message="$(string.keyword_Session1)" mask="0x400000000000"/>
    <keyword name="Session0" message="$(string.keyword_Session0)" mask="0x800000000000"/>
</keywords>

我不知道会话关键字的来源.这很令人讨厌,因为当我使用以下代码生成事件时,这些神奇创建的关键字会显示在事件日志中:

I don't understand where the session keywords come from. It is quite annoying because these magically created keywords show up in the eventlog when I use this code to generate an event:

[Event( 202, Message = "Writing Eventlog With keywords etc. {0}", Level = EventLevel.Verbose, Keywords = Keywords.Perf, Task = EventTask.None, Opcode = EventOpcode.Info, Channel = EventChannel.Debug )]
public void DebugWithKeywordEtc( string message )
{
    this.WriteEvent( 202, message );
}

已记录消息的关键字为Session0,Session1,Session2,Session3,Perf,该关键字源自事件xml <Keywords>0x4000f08000000000</Keywords>中的关键字值.

The keywords of the logged message read Session0,Session1,Session2,Session3,Perf, which derives from the keywords value in the event's xml <Keywords>0x4000f08000000000</Keywords>.

我已经自己创建了清单文件(使用ecmangen),在该清单中,关键字部分如下所示

I have already authored a manifest file myself (using ecmangen) and in that manifest, the keywords section looks like this

<keywords>
    <keyword name="DataBase" message="$(string.keyword_DataBase)" mask="0x1"/>
    <keyword name="Page" message="$(string.keyword_Page)" mask="0x2"/>
    <keyword name="Diagnostic" message="$(string.keyword_Diagnostic)" mask="0x4"/>
    <keyword name="Perf" message="$(string.keyword_Perf)" mask="0x8"/>
</keywords>

,将导致此事件xml:<Keywords>0x8000000000000001</Keywords>.这个结果显示得很好.

which results in this event xml: <Keywords>0x8000000000000001</Keywords>. This result is displayed perfectly fine.

推荐答案

EventSource自动定义并保留这些关键字以供自己使用.不幸的是,我不知道如何禁用此行为.

EventSource automatically defines and reserves those keywords for its own use. Unfortunately I don't know how to disable this behavior.

这篇关于如何在Microsoft.Diagnostics.Tracing.EventSource中正确定义关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆