44using System . Diagnostics ;
55using System . Linq ;
66using System . Net . Http ;
7- using System . Net . Http . Headers ;
87using Microsoft . Extensions . Logging ;
98using Splunk . Configurations ;
109using Splunk . Loggers ;
@@ -14,10 +13,9 @@ namespace Splunk.Providers
1413 /// <summary>
1514 /// This class is used to provide a Splunk HEC Raw logger for each categoryName.
1615 /// </summary>
17- public class SplunkHECRawLoggerProvider : ILoggerProvider
16+ public class SplunkHECRawLoggerProvider : SplunkHECBaseProvider , ILoggerProvider
1817 {
1918 readonly BatchManager batchManager ;
20- readonly HttpClient httpClient ;
2119 readonly LogLevel threshold ;
2220 readonly ILoggerFormatter loggerFormatter ;
2321 readonly ConcurrentDictionary < string , ILogger > loggers ;
@@ -35,38 +33,17 @@ public SplunkHECRawLoggerProvider(SplunkLoggerConfiguration configuration, ILogg
3533
3634 this . loggerFormatter = loggerFormatter ;
3735
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" ) ;
5537
5638 batchManager = new BatchManager ( configuration . HecConfiguration . BatchSizeCount , configuration . HecConfiguration . BatchIntervalInMiliseconds , Emit ) ;
5739 }
5840
59- ILogger CreateLoggerInstance ( string categoryName )
60- {
61- return new HECRawLogger ( categoryName , threshold , httpClient , batchManager , loggerFormatter ) ;
62- }
63-
6441 /// <summary>
6542 /// Create a <see cref="T:Splunk.Loggers.HECRawLogger"/> instance to the category name provided.
6643 /// </summary>
6744 /// <returns><see cref="T:Splunk.Loggers.HECRawLogger"/> instance.</returns>
6845 /// <param name="categoryName">Category name.</param>
69- public ILogger CreateLogger ( string categoryName )
46+ public override ILogger CreateLogger ( string categoryName )
7047 {
7148 return loggers . GetOrAdd ( categoryName , CreateLoggerInstance ( categoryName ) ) ;
7249 }
@@ -80,11 +57,21 @@ public ILogger CreateLogger(string categoryName)
8057 /// <see cref="Dispose"/>, you must release all references to the
8158 /// <see cref="T:Splunk.Providers.SplunkHECRawLoggerProvider"/> so the garbage collector can reclaim the memory
8259 /// that the <see cref="T:Splunk.Providers.SplunkHECRawLoggerProvider"/> was occupying.</remarks>
83- public void Dispose ( )
60+ public override void Dispose ( )
8461 {
8562 loggers . Clear ( ) ;
8663 }
8764
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+
8875 /// <summary>
8976 /// Method used to emit batched events.
9077 /// </summary>
0 commit comments