Description
Description
I'm honestly not sure if I'm just missing something simple but it seems like the EventAttribute.Message value is not being written in the underlying ETW event on Windows.
I was originally working with AOT and thought that could be the cause but when creating a reproducer to compare I found the non-AOT scenario was also missing this value.
Reproduction Steps
using System.Diagnostics.Tracing;
namespace EventTest;
[EventSource(Name = "MyEventSource")]
public sealed class MyEventSource : EventSource
{
public static MyEventSource Log = new();
private MyEventSource()
: base(EventSourceSettings.EtwSelfDescribingEventFormat)
{ }
[Event(1, Message = "foo {0}")]
public void MyEvent(string msg)
=> WriteEvent(1, msg);
}
public static class Program
{
public static void Main()
{
MyEventSource.Log.MyEvent("bar");
}
}
With the csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
I compiled with dotnet publish
and just ran the exe.
In my testing I am using my custom PowerShell module PSEtw by running the following in another admin PowerShell console when running the published exe from the above.
Trace-PSEtwEvent -Provider MyEventSource | % { $_ | ConvertTo-Json }
I've also reproduced the issue with PerfView and dotnet-trace and those are also missing the message data that I am expecting.
Expected behavior
{
"ProviderId": "8983a2e6-c5d2-5a1f-691f-db243cb1f681",
"ProviderName": "MyEventSource",
"ProcessId": 13420,
"ThreadId": 16120,
"TimeStamp": "2024-03-05T15:04:48.5560144Z",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"Id": 3,
"Version": 0,
"Channel": 11,
"ChannelName": null,
"Level": 4,
"LevelName": null,
"OpCode": 0,
"OpCodeName": null,
"Task": 0,
"TaskName": "MyEvent",
"Keyword": 263882790666240,
"KeywordNames": [],
"Tags": 0,
"EventData": [],
"Properties": [
{
"Name": "msg",
"Value": "bar",
"DisplayValue": "bar",
"Tags": 0
}
],
"EventMessage": "foo bar"
}
I expect EventMessage
to be the result of foo {0}
(foo bar
).
Actual behavior
{
"ProviderId": "8983a2e6-c5d2-5a1f-691f-db243cb1f681",
"ProviderName": "MyEventSource",
"ProcessId": 13420,
"ThreadId": 16120,
"TimeStamp": "2024-03-05T15:04:48.5560144Z",
"ActivityId": "00000000-0000-0000-0000-000000000000",
"Id": 3,
"Version": 0,
"Channel": 11,
"ChannelName": null,
"Level": 4,
"LevelName": null,
"OpCode": 0,
"OpCodeName": null,
"Task": 0,
"TaskName": "MyEvent",
"Keyword": 263882790666240,
"KeywordNames": [],
"Tags": 0,
"EventData": [],
"Properties": [
{
"Name": "msg",
"Value": "bar",
"DisplayValue": "bar",
"Tags": 0
}
],
"EventMessage": null
}
EventMessage
is not set. I've also noticed Task
is set to 0
not 1
as I would expect. This makes me even more suspicious I'm doing something wrong.
Regression?
I've gone back to net6.0
and it seems to have the same problem.
Known Workarounds
No response
Configuration
Running with .NET 8 on Windows Server 2022 x64.
Other information
No response