From c3a6ca31b039a2ec906bad0388d632d031217932 Mon Sep 17 00:00:00 2001 From: roshangavandi <37402152+roshangavandi@users.noreply.github.com> Date: Mon, 31 Jul 2023 22:58:15 -0700 Subject: [PATCH] Update HttpEventCollectorResendMiddleware.cs for splunk connection failed variable Updated HttpEventCollectorResendMiddleware.cs for splunk connection failed variable to switch splunk target using nlog.config --- .../HttpEventCollectorResendMiddleware.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 +}