1

I'm using System.Diagnostics to get some messages using EventSource, to trace them as a log. It appears that some informations are missing, as for example the EventMessage and the Message (they are empty), while the EventId and the Level are correctly set. The WriteEvent method is correct (The number and types of arguments passed to every event method exactly match what is passed to WriteEvent()). In particular, I am using WAD on a ServiceFabric Cluster to collect traces on an Azure Table Storage. Any idea?

Thanks!

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
user2867270
  • 161
  • 2
  • 8

2 Answers2

0

The parameters of the Event must match to the parameters of the method which you call. Eventsource builds the manifest based on the parameters of the method.

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.

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
0

I have had this problem ever since we upgraded to any version of the .NET Framework greater than 4.5.2. I finally figured out my problem and hopefully, this will help you too. I know this is an old post, but maybe it will help someone else as well.

It seems Event Tracing for Windows (ETW) handles errors and the only indication you get is what you're seeing where the logged message is null. I am using a custom formatter derived from IEventTextFormatter. (the EventData.FormattedMessage is null). Setting a breakpoint in this method showed the EventData.FormattedMessage was null. I also noticed the following messages in the Output/debug window in Visual Studio:

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

I traced my problem to the following method:

[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);
}

Based on the remarks in the docs on MSDN, the call to WriteEvent should include the EventId followed by all the arguments passed to your method. Evidently, the above code did not throw any exceptions in .NET Framework 4.5.2 or earlier.

When you implement a method that is identified as an ETW event in an EventSource-derived class. You must call the base class WriteEvent method passing the EventId and the same arguments as the implemented method.

My code now looks like this and works as expected. Good luck!

    [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);
    }
SteveB
  • 233
  • 3
  • 12