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()");
}
Stored procedure sp_trace_generateevent may be used to generate an event of type
user_event, which can be captured by a SQL Trace or Extended Event session. Specify a value of 82 through 91 for the @eventid parameter and the desired text for @userinfo:The pre-defined XEvent Profiler
StandardandTSQLsessions do not captureuser_eventbut you can include it in a custom XE session along with other XE events of interest. Below is example DDL to create a custom session with the same events as the XEvent ProfilerStandardquick trace plususer_event. After creation, the session can be started/viewed/stopped from SSMS similarly to other XE sessions.