1
1
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
13
13
{
14
14
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>
32
32
public abstract void Dispose ( ) ;
33
33
34
34
/// <summary>
35
35
/// Create a <see cref="T:Splunk.Loggers.HECJsonLogger"/> instance to the category name provided.
36
36
/// </summary>
37
37
/// <returns>The logger instance.</returns>
38
38
/// <param name="categoryName">Category name.</param>
39
- public abstract ILogger CreateLoggerInstance ( string categoryName ) ;
39
+ public abstract ILogger CreateLoggerInstance ( string categoryName ) ;
40
40
41
41
protected void SetupHttpClient ( SplunkLoggerConfiguration configuration , string endPointCustomization )
42
42
{
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 )
47
46
} ;
47
+
48
+ if ( configuration . HecConfiguration . DefaultTimeoutInMiliseconds > 0 )
49
+ httpClient . Timeout = TimeSpan . FromMilliseconds ( configuration . HecConfiguration . DefaultTimeoutInMiliseconds ) ;
50
+
48
51
httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Splunk" , configuration . HecConfiguration . Token ) ;
49
52
if ( configuration . HecConfiguration . ChannelIdType == HECConfiguration . ChannelIdOption . RequestHeader )
50
53
httpClient . DefaultRequestHeaders . Add ( "x-splunk-request-channel" , Guid . NewGuid ( ) . ToString ( ) ) ;
51
54
}
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 ) )
57
60
splunkCollectorUrl = splunkCollectorUrl + "/" ;
58
61
59
62
if ( ! string . IsNullOrWhiteSpace ( endPointCustomization ) )
@@ -68,7 +71,7 @@ Uri GetSplunkCollectorUrl(SplunkLoggerConfiguration configuration, string endPoi
68
71
splunkCollectorUrl = string . Format ( "{0}{1}{2}" , splunkCollectorUrl , splunkCollectorUrl . Contains ( "?" ) ? "&" : "?" , tokenParameter ) ;
69
72
}
70
73
71
- return new Uri ( splunkCollectorUrl ) ;
72
- }
73
- }
74
+ return new Uri ( splunkCollectorUrl ) ;
75
+ }
76
+ }
74
77
}
0 commit comments