@@ -10,27 +10,36 @@ internal class ExtractionMessage : FreshEntity
10
10
private static int messageCount = 0 ;
11
11
12
12
private readonly Message msg ;
13
+ private readonly bool bypassLimit ;
13
14
14
- public ExtractionMessage ( Context cx , Message msg ) : base ( cx )
15
+ public ExtractionMessage ( Context cx , Message msg ) : this ( cx , msg , bypassLimit : false )
15
16
{
17
+ }
18
+
19
+ private ExtractionMessage ( Context cx , Message msg , bool bypassLimit ) : base ( cx )
20
+ {
21
+ this . bypassLimit = bypassLimit ;
16
22
this . msg = msg ;
17
23
TryPopulate ( ) ;
18
24
}
19
25
20
26
protected override void Populate ( TextWriter trapFile )
21
27
{
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 )
25
29
{
26
- if ( messageCount == limit + 1 )
30
+ var val = Interlocked . Increment ( ref messageCount ) ;
31
+ if ( val > limit )
27
32
{
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 ;
29
39
}
30
- return ;
31
40
}
32
41
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 ,
34
43
msg . Location ?? Context . CreateLocation ( ) , msg . StackTrace ?? string . Empty ) ;
35
44
}
36
45
}
0 commit comments