KEMBAR78
TraceEvent Formatted Message is always null · Issue #70688 · dotnet/runtime · GitHub
Skip to content

TraceEvent Formatted Message is always null #70688

@mikelle-rogers

Description

@mikelle-rogers

Transferred from microsoft/perfview#1622 in perfview repo opened by Zheltov in the diagnostics repo.

Hello everyone!

I have been using DiagnosticsClient for subscribe to EventSource in same process. I have got events successfully, but TraceEvent.FormattedMessage is always null. However, i can see the message in Diagnostics Events window in Visual Studio.
What happened?

using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing;
using System;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Threading;
using System.Threading.Tasks;

namespace ETWSelfSignedAgentTest
{
class Program
{
static void Main(string[] args)
{
RunAgent();

        Task.Run(() =>
        {
            for(int i =0; i < int.MaxValue; i++)
            {
                ServiceEventSource.Log.Iteration(i);
                Thread.Sleep(1000);
            }
        });

        Console.ReadLine();
    }

    private static void RunAgent()
    {
        Task.Factory.StartNew(() =>
        {
            var client = new DiagnosticsClient(Process.GetCurrentProcess().Id);
            using var session = client.StartEventPipeSession(new EventPipeProvider[] { new EventPipeProvider("ExampleEventSource", EventLevel.Verbose, long.MaxValue) });
            using var source = new EventPipeEventSource(session.EventStream);
            source.Dynamic.All += (TraceEvent traceEvent) =>
            {
                Console.Write($"{traceEvent.ProviderName} [{traceEvent.Level}] FormattedMessage: {traceEvent.FormattedMessage}");
                foreach (string payloadName in traceEvent.PayloadNames)
                {
                    Console.Write($"{payloadName}: {traceEvent.PayloadStringByName(payloadName)}");
                }
                Console.WriteLine();
            };

            try
            {
                source.Process();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        },
        TaskCreationOptions.LongRunning);
    }
}

[EventSource(Name = "ExampleEventSource")]
public sealed class ServiceEventSource : EventSource
{
    public static readonly ServiceEventSource Log = new ServiceEventSource();

    private ServiceEventSource() : base() { }

    [Event(1, Level = EventLevel.Informational, Message = "It`s {0} iteration")]
    public void Iteration(int i)
    {
        WriteEvent(1, i);
    }
}

}
im_console

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions