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