diff --git a/src/NLog.Targets.Splunk/Splunk.Logging.Common/HttpEventCollectorResendMiddleware.cs b/src/NLog.Targets.Splunk/Splunk.Logging.Common/HttpEventCollectorResendMiddleware.cs index 3cdc169..3618916 100644 --- a/src/NLog.Targets.Splunk/Splunk.Logging.Common/HttpEventCollectorResendMiddleware.cs +++ b/src/NLog.Targets.Splunk/Splunk.Logging.Common/HttpEventCollectorResendMiddleware.cs @@ -115,6 +115,8 @@ public async Task Plugin( } if (statusCode != HttpStatusCode.OK || webException != null) { + // when splunk connectivity is failed then set status to failed.This status help to switch target in nlog config file + GlobalDiagnosticsContext.Set("splunkstatus", "failed"); throw new HttpEventCollectorException( code: statusCode == HttpStatusCode.OK ? HttpStatusCode.InternalServerError : statusCode, webException: webException, @@ -123,7 +125,11 @@ public async Task Plugin( serializedEvents: System.Text.Encoding.UTF8.GetString(serializedEvents) ); } + else{ + // when splunk connectivity is failed then set status to failed + GlobalDiagnosticsContext.Set("splunkstatus", "success"); + } return response; } } -} \ No newline at end of file +}