File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,15 +55,15 @@ public void CommandStart(string sql)
5555 {
5656 Interlocked . Increment ( ref _totalCommands ) ;
5757 Interlocked . Increment ( ref _currentCommands ) ;
58- WriteEvent ( CommandStartId , sql ) ;
58+ NpgsqlSqlEventSource . CommandStart ( sql ) ;
5959 }
6060
6161 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
6262 [ Event ( CommandStopId , Level = EventLevel . Informational ) ]
6363 public void CommandStop ( )
6464 {
6565 Interlocked . Decrement ( ref _currentCommands ) ;
66- WriteEvent ( CommandStopId ) ;
66+ NpgsqlSqlEventSource . CommandStop ( ) ;
6767 }
6868
6969 internal void CommandStartPrepared ( ) => Interlocked . Increment ( ref _totalPreparedCommands ) ;
Original file line number Diff line number Diff line change 1+ using System . Diagnostics . Tracing ;
2+ using System . Runtime . CompilerServices ;
3+
4+ namespace Npgsql
5+ {
6+ sealed class NpgsqlSqlEventSource : EventSource
7+ {
8+ static readonly NpgsqlSqlEventSource Log = new NpgsqlSqlEventSource ( ) ;
9+
10+ const string EventSourceName = "Npgsql.Sql" ;
11+
12+ const int CommandStartId = 3 ;
13+ const int CommandStopId = 4 ;
14+
15+ internal NpgsqlSqlEventSource ( ) : base ( EventSourceName ) { }
16+
17+ // NOTE
18+ // - The 'Start' and 'Stop' suffixes on the following event names have special meaning in EventSource. They
19+ // enable creating 'activities'.
20+ // For more information, take a look at the following blog post:
21+ // https://blogs.msdn.microsoft.com/vancem/2015/09/14/exploring-eventsource-activity-correlation-and-causation-features/
22+ // - A stop event's event id must be next one after its start event.
23+
24+ [ Event ( CommandStartId , Level = EventLevel . Informational ) ]
25+ public static void CommandStart ( string sql ) => Log . WriteEvent ( CommandStartId , sql ) ;
26+
27+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
28+ [ Event ( CommandStopId , Level = EventLevel . Informational ) ]
29+ public static void CommandStop ( ) => Log . WriteEvent ( CommandStopId ) ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments