@@ -455,64 +455,14 @@ public void NLogTargetFlushesTelemetryClient()
455455 NLog . Common . AsyncContinuation asyncContinuation = ( ex ) => { flushException = ex ; flushEvent . Set ( ) ; } ;
456456 aiLogger . Factory . Flush ( asyncContinuation , 5000 ) ;
457457 Assert . IsTrue ( flushEvent . WaitOne ( 5000 ) ) ;
458- Assert . IsNotNull ( flushException ) ;
459- Assert . AreEqual ( "Flush called" , flushException . Message ) ;
460458 }
461459
462460 [ TestMethod ]
463461 [ TestCategory ( "NLogTarget" ) ]
464- public void NLogInfoIsSentAsInformationTraceItemWithAIConnectionString ( )
462+ public void NLogTargetWithConnectionString ( )
465463 {
466- var aiLogger = this . CreateTargetWithGivenConnectionString ( "Your_ApplicationInsights_ConnectionString" ) ;
467- aiLogger . Info ( "Info message" ) ;
468-
469- var telemetry = ( TraceTelemetry ) this . adapterHelper . Channel . SentItems . First ( ) ;
470- Assert . AreEqual ( $ "Info message", telemetry . Message ) ;
471- }
472-
473- [ TestMethod ]
474- [ TestCategory ( "NLogTarget" ) ]
475- public void NLogTraceIsSentAsVerboseTraceItemWithAIConnectionString ( )
476- {
477- var aiLogger = this . CreateTargetWithGivenConnectionString ( "Your_ApplicationInsights_ConnectionString" ) ;
478- aiLogger . Trace ( "Trace message" ) ;
479-
480- var telemetry = ( TraceTelemetry ) this . adapterHelper . Channel . SentItems . FirstOrDefault ( ) ;
481- Assert . AreEqual ( "Trace message" , telemetry . Message ) ;
482- }
483-
484- [ TestMethod ]
485- [ TestCategory ( "NLogTarget" ) ]
486- public void NLogDebugIsSentAsVerboseTraceItemWithAIConnectionString ( )
487- {
488- var aiLogger = this . CreateTargetWithGivenConnectionString ( "Your_ApplicationInsights_ConnectionString" ) ;
489- aiLogger . Debug ( "Debug Message" ) ;
490-
491- var telemetry = ( TraceTelemetry ) this . adapterHelper . Channel . SentItems . FirstOrDefault ( ) ;
492- Assert . AreEqual ( "Debug Message" , telemetry . Message ) ;
493- }
494-
495- [ TestMethod ]
496- [ TestCategory ( "NLogTarget" ) ]
497- public void NLogWarnIsSentAsWarningTraceItemWithAIConnectionString ( )
498- {
499- var aiLogger = this . CreateTargetWithGivenConnectionString ( "Your_ApplicationInsights_ConnectionString" ) ;
500-
501- aiLogger . Warn ( "Warn message" ) ;
502-
503- var telemetry = ( TraceTelemetry ) this . adapterHelper . Channel . SentItems . FirstOrDefault ( ) ;
504- Assert . AreEqual ( "Warn message" , telemetry . Message ) ;
505- }
506-
507- [ TestMethod ]
508- [ TestCategory ( "NLogTarget" ) ]
509- public void NLogErrorIsSentAsVerboseTraceItemWithAIConnectionString ( )
510- {
511- var aiLogger = this . CreateTargetWithGivenConnectionString ( "InstrumentationKey=b91a8f48-c77c-4f12-80e2-f96bc1abb126;IngestionEndpoint=https://centralus-2.in.applicationinsights.azure.com/;LiveEndpoint=https://centralus.livediagnostics.monitor.azure.com/" ) ;
512- aiLogger . Error ( "Error Message" ) ;
513-
514- var telemetry = ( TraceTelemetry ) this . adapterHelper . Channel . SentItems . FirstOrDefault ( ) ;
515- Assert . AreEqual ( "Error Message" , telemetry . Message ) ;
464+ var aiLogger = this . CreateTargetWithGivenConnectionString ( "TestAI" ) ;
465+ VerifyMessagesInMockChannel ( aiLogger , "TestAI" ) ;
516466 }
517467
518468 private void VerifyMessagesInMockChannel ( Logger aiLogger , string instrumentationKey )
@@ -562,19 +512,16 @@ private Logger CreateTargetWithGivenInstrumentationKey(
562512 }
563513
564514 private Logger CreateTargetWithGivenConnectionString (
565- string connectionString = "Your_ApplicationInsights_ConnectionString " ,
515+ string instrumentationKey = "TEST " ,
566516 Action < Logger > loggerAction = null )
567517 {
568- // Mock channel to validate that our appender is trying to send logs
569- #pragma warning disable CS0618 // Type or member is obsolete
570- TelemetryConfiguration . Active . TelemetryChannel = this . adapterHelper . Channel ;
571- #pragma warning restore CS0618 // Type or member is obsolete
572-
573518 ApplicationInsightsTarget target = new ApplicationInsightsTarget
574519 {
575- ConnectionString = connectionString
520+ ConnectionString = $ "InstrumentationKey= { instrumentationKey } ;IngestionEndpoint=https://localhost/;LiveEndpoint=https://localhost/"
576521 } ;
577522
523+ target . TelemetryConfigurationFactory = ( ) => new TelemetryConfiguration ( ) { TelemetryChannel = this . adapterHelper . Channel } ;
524+
578525 LoggingRule rule = new LoggingRule ( "*" , LogLevel . Trace , target ) ;
579526 LoggingConfiguration config = new LoggingConfiguration ( ) ;
580527 config . AddTarget ( "AITarget" , target ) ;
0 commit comments