-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
area-System.Diagnostics.TracingenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
area-System.Diagnostics.TracingenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions
