Skip to content

Commit fabfa40

Browse files
author
Prasad Muley
committed
HttpClient.Timeout should not be set to 0 but HttpClient.Timeouts default value should be used
1 parent abdc246 commit fabfa40

File tree

2 files changed

+46
-43
lines changed

2 files changed

+46
-43
lines changed

src/SplunkLogger/Configurations/HECConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public enum ChannelIdOption
1414
}
1515

1616
/// <summary>
17-
/// Gets or sets the batch interval in miliseconds (default 1000).
17+
/// Gets or sets the batch interval in miliseconds.
1818
/// </summary>
19-
public uint BatchIntervalInMiliseconds { get; set; } = 1000;
19+
public uint BatchIntervalInMilliseconds { get; set; }
2020

2121
/// <summary>
2222
/// Gets or sets the batch size count.
Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
using System;
2-
using System.Net.Http;
3-
using System.Net.Http.Headers;
4-
using Microsoft.Extensions.Logging;
5-
using Splunk.Configurations;
6-
7-
namespace Splunk.Providers
8-
{
9-
/// <summary>
10-
/// Splunk HECB ase provider.
11-
/// </summary>
12-
public abstract class SplunkHECBaseProvider : ILoggerProvider
2+
using System.Net.Http;
3+
using System.Net.Http.Headers;
4+
using Microsoft.Extensions.Logging;
5+
using Splunk.Configurations;
6+
7+
namespace Splunk.Providers
8+
{
9+
/// <summary>
10+
/// Splunk HECB ase provider.
11+
/// </summary>
12+
public abstract class SplunkHECBaseProvider : ILoggerProvider
1313
{
1414
protected HttpClient httpClient;
15-
16-
/// <summary>
17-
/// Get a <see cref="T:Splunk.Loggers.HECJsonLogger"/> instance to the category name provided.
18-
/// </summary>
19-
/// <returns><see cref="T:Splunk.Loggers.HECJsonLogger"/> instance.</returns>
20-
/// <param name="categoryName">Category name.</param>
21-
public abstract ILogger CreateLogger(string categoryName);
22-
23-
/// <summary>
24-
/// Releases all resource used by the <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> object.
25-
/// </summary>
26-
/// <remarks>Call <see cref="Dispose"/> when you are finished using the
27-
/// <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/>. The <see cref="Dispose"/> method leaves the
28-
/// <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> in an unusable state. After calling
29-
/// <see cref="Dispose"/>, you must release all references to the
30-
/// <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> so the garbage collector can reclaim the memory
31-
/// that the <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> was occupying.</remarks>
15+
16+
/// <summary>
17+
/// Get a <see cref="T:Splunk.Loggers.HECJsonLogger"/> instance to the category name provided.
18+
/// </summary>
19+
/// <returns><see cref="T:Splunk.Loggers.HECJsonLogger"/> instance.</returns>
20+
/// <param name="categoryName">Category name.</param>
21+
public abstract ILogger CreateLogger(string categoryName);
22+
23+
/// <summary>
24+
/// Releases all resource used by the <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> object.
25+
/// </summary>
26+
/// <remarks>Call <see cref="Dispose"/> when you are finished using the
27+
/// <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/>. The <see cref="Dispose"/> method leaves the
28+
/// <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> in an unusable state. After calling
29+
/// <see cref="Dispose"/>, you must release all references to the
30+
/// <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> so the garbage collector can reclaim the memory
31+
/// that the <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> was occupying.</remarks>
3232
public abstract void Dispose();
3333

3434
/// <summary>
3535
/// Create a <see cref="T:Splunk.Loggers.HECJsonLogger"/> instance to the category name provided.
3636
/// </summary>
3737
/// <returns>The logger instance.</returns>
3838
/// <param name="categoryName">Category name.</param>
39-
public abstract ILogger CreateLoggerInstance(string categoryName);
39+
public abstract ILogger CreateLoggerInstance(string categoryName);
4040

4141
protected void SetupHttpClient(SplunkLoggerConfiguration configuration, string endPointCustomization)
4242
{
43-
httpClient = new HttpClient
44-
{
45-
BaseAddress = GetSplunkCollectorUrl(configuration, endPointCustomization),
46-
Timeout = TimeSpan.FromMilliseconds(configuration.HecConfiguration.DefaultTimeoutInMiliseconds)
43+
httpClient = new HttpClient
44+
{
45+
BaseAddress = GetSplunkCollectorUrl(configuration, endPointCustomization)
4746
};
47+
48+
if (configuration.HecConfiguration.DefaultTimeoutInMiliseconds > 0)
49+
httpClient.Timeout = TimeSpan.FromMilliseconds(configuration.HecConfiguration.DefaultTimeoutInMiliseconds);
50+
4851
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", configuration.HecConfiguration.Token);
4952
if (configuration.HecConfiguration.ChannelIdType == HECConfiguration.ChannelIdOption.RequestHeader)
5053
httpClient.DefaultRequestHeaders.Add("x-splunk-request-channel", Guid.NewGuid().ToString());
5154
}
52-
53-
Uri GetSplunkCollectorUrl(SplunkLoggerConfiguration configuration, string endPointCustomization)
54-
{
55-
var splunkCollectorUrl = configuration.HecConfiguration.SplunkCollectorUrl;
56-
if (!splunkCollectorUrl.EndsWith("/", StringComparison.InvariantCulture))
55+
56+
Uri GetSplunkCollectorUrl(SplunkLoggerConfiguration configuration, string endPointCustomization)
57+
{
58+
var splunkCollectorUrl = configuration.HecConfiguration.SplunkCollectorUrl;
59+
if (!splunkCollectorUrl.EndsWith("/", StringComparison.InvariantCulture))
5760
splunkCollectorUrl = splunkCollectorUrl + "/";
5861

5962
if(!string.IsNullOrWhiteSpace(endPointCustomization))
@@ -68,7 +71,7 @@ Uri GetSplunkCollectorUrl(SplunkLoggerConfiguration configuration, string endPoi
6871
splunkCollectorUrl = string.Format("{0}{1}{2}", splunkCollectorUrl, splunkCollectorUrl.Contains("?") ? "&" : "?", tokenParameter);
6972
}
7073

71-
return new Uri(splunkCollectorUrl);
72-
}
73-
}
74+
return new Uri(splunkCollectorUrl);
75+
}
76+
}
7477
}

0 commit comments

Comments
 (0)