微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 为什么限制参数类型和对EventSource方法的计数

我现在正在用C#中的Microsoft EventSources进行实验.
一个限制如下

…The number and types of arguments passed to the ETW method must
exactly match the types passed to the WriteEvent overload it calls.
For example:

[Event(2,Level = EventLevel.informational)] 
public void Info(string message,int count) 
{
   base.WriteEvent(2,message,count); 
}

这基本上限制了您在EventSource类中编写更丰富的API.这基本上意味着您无法创建接收自定义对象的方法,并且在方法体内可以将其序列化为字符串(或WriteEvent重载支持的其他类型).

您唯一能决定的是方法名称以及反映WriteEvent重载的参数名称和计数.
还是我错了?

解决方法

这是构建清单文件所必需的. The_EventSourceUsersGuide.docx解释了它:

Event methods must match exactly the types of the WriteEvent overload it calls,in particular you should avoid implicit scalar conversions; they are dangerous because the manifest is generated based on the signature of the ETW event method,but the values passed to ETW are based on the signature of the WriteEvent overload.

原文地址:https://www.jb51.cc/csharp/97366.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐