4
4
using System . Diagnostics ;
5
5
using System . Linq ;
6
6
using System . Net . Http ;
7
- using System . Net . Http . Headers ;
8
7
using Microsoft . Extensions . Logging ;
9
8
using Splunk . Configurations ;
10
9
using Splunk . Loggers ;
@@ -14,10 +13,9 @@ namespace Splunk.Providers
14
13
/// <summary>
15
14
/// This class is used to provide a Splunk HEC Raw logger for each categoryName.
16
15
/// </summary>
17
- public class SplunkHECRawLoggerProvider : ILoggerProvider
16
+ public class SplunkHECRawLoggerProvider : SplunkHECBaseProvider , ILoggerProvider
18
17
{
19
18
readonly BatchManager batchManager ;
20
- readonly HttpClient httpClient ;
21
19
readonly LogLevel threshold ;
22
20
readonly ILoggerFormatter loggerFormatter ;
23
21
readonly ConcurrentDictionary < string , ILogger > loggers ;
@@ -35,38 +33,17 @@ public SplunkHECRawLoggerProvider(SplunkLoggerConfiguration configuration, ILogg
35
33
36
34
this . loggerFormatter = loggerFormatter ;
37
35
38
- httpClient = new HttpClient ( ) ;
39
-
40
- var splunkCollectorUrl = configuration . HecConfiguration . SplunkCollectorUrl ;
41
- if ( ! splunkCollectorUrl . EndsWith ( "/" , StringComparison . InvariantCulture ) )
42
- splunkCollectorUrl += "/" ;
43
-
44
- if ( configuration . HecConfiguration . ChannelIdType == HECConfiguration . ChannelIdOption . QueryString )
45
- splunkCollectorUrl = splunkCollectorUrl + "raw?channel=" + Guid . NewGuid ( ) . ToString ( ) ;
46
-
47
- httpClient . BaseAddress = new Uri ( splunkCollectorUrl ) ;
48
-
49
- httpClient . Timeout = TimeSpan . FromMilliseconds ( configuration . HecConfiguration . DefaultTimeoutInMiliseconds ) ;
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 ( ) ) ;
36
+ SetupHttpClient ( configuration , "raw" ) ;
55
37
56
38
batchManager = new BatchManager ( configuration . HecConfiguration . BatchSizeCount , configuration . HecConfiguration . BatchIntervalInMiliseconds , Emit ) ;
57
39
}
58
40
59
- ILogger CreateLoggerInstance ( string categoryName )
60
- {
61
- return new HECRawLogger ( categoryName , threshold , httpClient , batchManager , loggerFormatter ) ;
62
- }
63
-
64
41
/// <summary>
65
42
/// Create a <see cref="T:Splunk.Loggers.HECRawLogger"/> instance to the category name provided.
66
43
/// </summary>
67
44
/// <returns><see cref="T:Splunk.Loggers.HECRawLogger"/> instance.</returns>
68
45
/// <param name="categoryName">Category name.</param>
69
- public ILogger CreateLogger ( string categoryName )
46
+ public override ILogger CreateLogger ( string categoryName )
70
47
{
71
48
return loggers . GetOrAdd ( categoryName , CreateLoggerInstance ( categoryName ) ) ;
72
49
}
@@ -80,11 +57,21 @@ public ILogger CreateLogger(string categoryName)
80
57
/// <see cref="Dispose"/>, you must release all references to the
81
58
/// <see cref="T:Splunk.Providers.SplunkHECRawLoggerProvider"/> so the garbage collector can reclaim the memory
82
59
/// that the <see cref="T:Splunk.Providers.SplunkHECRawLoggerProvider"/> was occupying.</remarks>
83
- public void Dispose ( )
60
+ public override void Dispose ( )
84
61
{
85
62
loggers . Clear ( ) ;
86
63
}
87
64
65
+ /// <summary>
66
+ /// Create a <see cref="T:Splunk.Loggers.HECRawLogger"/> instance to the category name provided.
67
+ /// </summary>
68
+ /// <returns><see cref="T:Splunk.Loggers.HECRawLogger"/> instance.</returns>
69
+ /// <param name="categoryName">Category name.</param>
70
+ public override ILogger CreateLoggerInstance ( string categoryName )
71
+ {
72
+ return new HECRawLogger ( categoryName , threshold , httpClient , batchManager , loggerFormatter ) ;
73
+ }
74
+
88
75
/// <summary>
89
76
/// Method used to emit batched events.
90
77
/// </summary>
0 commit comments