@@ -11,9 +11,14 @@ internal sealed class Fixture
1111 {
1212 public Fixture ( )
1313 {
14+ DiagnosticLogger = new InMemoryDiagnosticLogger ( ) ;
1415 Hub = Substitute . For < IHub > ( ) ;
1516 ScopeManager = Substitute . For < IInternalScopeManager > ( ) ;
16- Options = new SentryOptions ( ) ;
17+ Options = new SentryOptions
18+ {
19+ Debug = true ,
20+ DiagnosticLogger = DiagnosticLogger ,
21+ } ;
1722 Clock = new MockClock ( new DateTimeOffset ( 2025 , 04 , 22 , 14 , 51 , 00 , TimeSpan . Zero ) ) ;
1823 Span = Substitute . For < ISpan > ( ) ;
1924 TraceId = SentryId . Create ( ) ;
@@ -24,6 +29,7 @@ public Fixture()
2429 Span . ParentSpanId . Returns ( ParentSpanId ) ;
2530 }
2631
32+ public InMemoryDiagnosticLogger DiagnosticLogger { get ; }
2733 public IHub Hub { get ; }
2834 public IInternalScopeManager ScopeManager { get ; }
2935 public SentryOptions Options { get ; }
@@ -147,6 +153,22 @@ public void Log_WhenBeforeSendLogReturnsNull_DoesNotCaptureEnvelope()
147153 invocations . Should ( ) . Be ( 1 ) ;
148154 }
149155
156+ [ Fact ]
157+ public void Log_InvalidFormat_DoesNotCaptureEnvelope ( )
158+ {
159+ _fixture . Options . EnableLogs = true ;
160+ var logger = _fixture . GetSut ( ) ;
161+
162+ logger . LogTrace ( "Template string with arguments: {0}, {1}, {2}, {3}, {4}" , [ "string" , true , 1 , 2.2 ] ) ;
163+
164+ _fixture . Hub . Received ( 0 ) . CaptureEnvelope ( Arg . Any < Envelope > ( ) ) ;
165+ var entry = _fixture . DiagnosticLogger . Entries . Should ( ) . ContainSingle ( ) . Which ;
166+ entry . Level . Should ( ) . Be ( SentryLevel . Error ) ;
167+ entry . Message . Should ( ) . Be ( "Template string does not match the provided argument." ) ;
168+ entry . Exception . Should ( ) . BeOfType < FormatException > ( ) ;
169+ entry . Args . Should ( ) . BeEmpty ( ) ;
170+ }
171+
150172 private static void ConfigureLog ( SentryLog log )
151173 {
152174 log . SetAttribute ( "attribute-key" , "attribute-value" ) ;
0 commit comments