I want to be able to read all XE files for a dynamic XE session name. My XE session stores files to disk.

I have the query below

SELECT  @Path = (
                    SELECT  CONVERT(XML,target_data).value('(/EventFileTarget/File/@name)[1]', 'NVARCHAR(MAX)') AS [Path]
                    FROM    sys.dm_xe_sessions s
                            JOIN sys.dm_xe_session_targets t
                                ON s.address = t.event_session_address
                    WHERE   s.name = @XeName

SELECT  event_data = CONVERT(XML, event_data) 
FROM    sys.fn_xe_file_target_read_file(@Path, NULL, NULL, NULL)

However, the target_data column in sys.dm_xe_session_targets only shows the most recent file in the format C:\Trace Outputs\MyXE\MyXE_0_132109395357410000.xel

but I need it to be C:\Trace Outputs\MyXE\MyXE*.xel

I can do this using some string functions to find the first _ after the last \ and replace that and all the text after with *.xel but I wondered if there was a nicer / easier way to do this than a load of nested string manipulation functions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.