Share via

How can I write events to the XEvent Profiler

David Thielen 3,231 Reputation points
2024-03-13T16:03:17.92+00:00

Hi all;

Is there a way to write a string to the XEvent profiler that will then put it in the profiler output? What I want to do is in my OnInitializeAsync() method (my app is Blazor Server using Entity Framework) is write to the XProfiler event list at the start, and again at the end of the method. That way I can see what SQL queries occurred in that method.

If there is no explicit way to do this, would I have any problems doing the following (it works, just asking if it's going to cause me problems)

if (debugMode) {
    await dbContext.Database.ExecuteSqlAsync("-- starting Dashboard.OnInitializeAsync()");
}

And while the above "works", it's ugly in the output (see below). So something better would be great.

exec sp_executesql N'EXEC sp_trace_generateevent @eventid = 82, @userinfo = N''@p0'';',N'@p0 nvarchar(4000)',@p0=N'Leaving Dashboard.OnInitializedAsync()'

thanks - dave

Community Center | Not monitored
SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.