Skip to content

Commit 1595234

Browse files
committed
Enabled send channelId via query string and also turned it optional
#36 #34
1 parent fabef9f commit 1595234

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/SplunkLogger/Providers/SplunkHECRawLoggerProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ public SplunkHECRawLoggerProvider(SplunkLoggerConfiguration configuration, ILogg
4040
var splunkCollectorUrl = configuration.HecConfiguration.SplunkCollectorUrl;
4141
if (!splunkCollectorUrl.EndsWith("/", StringComparison.InvariantCulture))
4242
splunkCollectorUrl += "/";
43-
44-
var baseAddress = new Uri(splunkCollectorUrl + "raw?channel=" + Guid.NewGuid().ToString());
45-
httpClient.BaseAddress = baseAddress;
43+
44+
if(configuration.HecConfiguration.ChannelIdType == HECConfiguration.ChannelIdOption.QueryString)
45+
splunkCollectorUrl = splunkCollectorUrl + "raw?channel=" + Guid.NewGuid().ToString();
46+
47+
httpClient.BaseAddress = new Uri(splunkCollectorUrl);
4648

4749
httpClient.Timeout = TimeSpan.FromMilliseconds(configuration.HecConfiguration.DefaultTimeoutInMiliseconds);
48-
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", configuration.HecConfiguration.Token);
50+
51+
if(!configuration.HecConfiguration.UseTokenAsQueryString)
52+
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", configuration.HecConfiguration.Token);
53+
if (configuration.HecConfiguration.ChannelIdType == HECConfiguration.ChannelIdOption.RequestHeader)
54+
httpClient.DefaultRequestHeaders.Add("x-splunk-request-channel", Guid.NewGuid().ToString());
4955

5056
batchManager = new BatchManager(configuration.HecConfiguration.BatchSizeCount, configuration.HecConfiguration.BatchIntervalInMiliseconds, Emit);
5157
}

0 commit comments

Comments
 (0)