我使用System.Diagnostics获取一些使用EventSource的消息,并将它们作为日志进行跟踪。似乎缺少一些信息,例如EventMessage和消息(它们是空的),而EventId和级别被正确设置。WriteEvent方法是正确的(传递给每个事件方法的参数的数量和类型与传递给WriteEvent()的参数完全匹配)。特别是,我正在使用ServiceFabric集群上的WAD来收集Azure表存储中的跟踪。有什么想法吗?
谢谢!
发布于 2016-01-16 16:02:16
事件的参数必须与调用的方法的参数匹配。事件源基于方法的参数构建清单。
事件方法必须完全匹配它调用的WriteEvent重载的类型,特别是您应该避免隐式标量转换;它们是危险的,因为清单是根据ETW事件方法的签名生成的,但是传递给WriteEvent重载的值基于WriteEvent重载的签名。
发布于 2018-05-11 13:06:00
自从我们升级到任何大于4.5.2的.NET框架版本之后,我就遇到了这个问题。我终于解决了我的问题,希望这也能帮到你。我知道这是一个旧的职位,但也许它也会帮助其他人。
Windows的事件跟踪(ETW)似乎处理错误,唯一的指示就是看到记录的消息为null。我正在使用从IEventTextFormatter派生的自定义格式化程序。( EventData.FormattedMessage为空)。在此方法中设置断点显示EventData.FormattedMessage为null。我还注意到Visual中输出/调试窗口中的以下消息:
The parameters to the Event method do not match the parameters to the WriteEvent method. This may cause the event to be displayed incorrectly.
EventSourceException while processing event "WriteLogDefault": System.IndexOutOfRangeException:Index was outside the bounds of the array.
A first chance exception of type 'System.NullReferenceException' occurred in NEAM.App.ProfileDataMart.BL.dll我将我的问题归结于以下方法:
[Event(1, Message = "{2}", Level = EventLevel.Informational, Keywords = Keywords.Informational)]
private void WriteLogDefault(int p_EventId, string p_AssemblyName, int p_Key, string p_Message)
{
WriteEvent(p_EventId, p_AssemblyName, p_Key, p_Message);
}根据MSDN上docs中的注释,对WriteEvent的调用应该包括EventId,后面跟着传递给您的方法的所有参数。显然,上面的代码在.NET Framework4.5.2或更高版本中没有抛出任何异常。
在事件源派生类中实现标识为ETW事件的方法时。必须调用基类WriteEvent方法,传递EventId和与已实现方法相同的参数。
我的代码现在看起来和预期的一样工作。祝好运!
[Event(1, Message = "{2}", Level = EventLevel.Informational, Keywords = Keywords.Informational)]
public void WriteLogDefault(string p_AssemblyName, int p_Key, string p_Message)
{
WriteEvent(1, p_AssemblyName, p_Key, p_Message);
}https://stackoverflow.com/questions/34824820
复制相似问题