@@ -10,27 +10,36 @@ internal class ExtractionMessage : FreshEntity
1010 private static int messageCount = 0 ;
1111
1212 private readonly Message msg ;
13+ private readonly bool bypassLimit ;
1314
14- public ExtractionMessage ( Context cx , Message msg ) : base ( cx )
15+ public ExtractionMessage ( Context cx , Message msg ) : this ( cx , msg , bypassLimit : false )
1516 {
17+ }
18+
19+ private ExtractionMessage ( Context cx , Message msg , bool bypassLimit ) : base ( cx )
20+ {
21+ this . bypassLimit = bypassLimit ;
1622 this . msg = msg ;
1723 TryPopulate ( ) ;
1824 }
1925
2026 protected override void Populate ( TextWriter trapFile )
2127 {
22- // The below doesn't limit the extractor messages to the exact limit, but it's good enough.
23- Interlocked . Increment ( ref messageCount ) ;
24- if ( messageCount > limit )
28+ if ( ! bypassLimit )
2529 {
26- if ( messageCount == limit + 1 )
30+ var val = Interlocked . Increment ( ref messageCount ) ;
31+ if ( val > limit )
2732 {
28- Context . ExtractionContext . Logger . LogWarning ( $ "Stopped logging extractor messages after reaching { limit } ") ;
33+ if ( val == limit + 1 )
34+ {
35+ Context . ExtractionContext . Logger . LogWarning ( $ "Stopped logging extractor messages after reaching { limit } ") ;
36+ _ = new ExtractionMessage ( Context , new Message ( $ "Stopped logging extractor messages after reaching { limit } ", null , null , null , Util . Logging . Severity . Warning ) , bypassLimit : true ) ;
37+ }
38+ return ;
2939 }
30- return ;
3140 }
3241
33- trapFile . extractor_messages ( this , msg . Severity , "C# extractor" , msg . Text , msg . EntityText ?? string . Empty ,
42+ trapFile . extractor_messages ( this , msg . Severity , msg . Text , msg . EntityText ?? string . Empty ,
3443 msg . Location ?? Context . CreateLocation ( ) , msg . StackTrace ?? string . Empty ) ;
3544 }
3645 }
0 commit comments