Basically, this question with a difference...
Is it possible to capture print output from a TSQL stored procedure in .NET, using the Entity Framework?
The so
Based on the answer from @samneric, but with some modifications for EF Core we used this to allow debugging of a wayward stored procedure;
DbConnection connection = Database.GetDbConnection();
var sqlConnection = connection as SqlConnection;
sqlConnection.InfoMessage += (s, a) => System.Diagnostics.Debug.WriteLine(a.Message);