@@ -984,9 +984,9 @@ internal long TrySNIScopeEnterEvent(string className, [System.Runtime.CompilerSe
984984 {
985985 if ( Log . IsSNIScopeEnabled ( ) )
986986 {
987- StringBuilder sb = new StringBuilder ( className ) ;
988- sb . Append ( "." ) . Append ( memberName ) . Append ( " | SNI | INFO | SCOPE | Entering Scope {0 }") ;
989- return SNIScopeEnter ( sb . ToString ( ) ) ;
987+ long scopeId = Interlocked . Increment ( ref s_nextSNIScopeId ) ;
988+ WriteEvent ( SNIScopeEnterId , $ " { className } . { memberName } | SNI | INFO | SCOPE | Entering Scope { scopeId } ") ;
989+ return scopeId ;
990990 }
991991 return 0 ;
992992 }
@@ -1017,7 +1017,6 @@ internal void BeginExecute(int objectId, string dataSource, string database, str
10171017 [ Event ( EndExecuteEventId , Keywords = Keywords . ExecutionTrace , Task = Tasks . ExecuteCommand , Opcode = EventOpcode . Stop ) ]
10181018 internal void EndExecute ( int objectId , int compositestate , int sqlExceptionNumber , string message )
10191019 {
1020-
10211020 WriteEvent ( EndExecuteEventId , objectId , compositestate , sqlExceptionNumber , message ) ;
10221021 }
10231022
@@ -1130,10 +1129,17 @@ internal static class EventType
11301129 private readonly long _scopeId ;
11311130
11321131 public TrySNIEventScope ( long scopeID ) => _scopeId = scopeID ;
1133- public void Dispose ( ) =>
1134- SqlClientEventSource . Log . SNIScopeLeave ( string . Format ( "Exit SNI Scope {0}" , _scopeId ) ) ;
1132+ public void Dispose ( )
1133+ {
1134+ if ( _scopeId == 0 )
1135+ {
1136+ return ;
1137+ }
1138+ SqlClientEventSource . Log . TrySNIScopeLeaveEvent ( _scopeId ) ;
1139+ }
11351140
1136- public static TrySNIEventScope Create ( string message ) => new TrySNIEventScope ( SqlClientEventSource . Log . SNIScopeEnter ( message ) ) ;
1141+ public static TrySNIEventScope Create ( string className , [ System . Runtime . CompilerServices . CallerMemberName ] string memberName = "" )
1142+ => new TrySNIEventScope ( SqlClientEventSource . Log . TrySNIScopeEnterEvent ( className , memberName ) ) ;
11371143 }
11381144
11391145 internal readonly ref struct TryEventScope //: IDisposable
0 commit comments