@@ -13,8 +13,14 @@ namespace Splunk.Providers
13
13
/// </summary>
14
14
public abstract class SplunkHECBaseProvider : ILoggerProvider
15
15
{
16
+ protected ILogger loggerInstance ;
16
17
protected HttpClient httpClient ;
17
18
19
+ public SplunkHECBaseProvider ( SplunkLoggerConfiguration configuration , string endPointCustomization )
20
+ {
21
+ SetupHttpClient ( configuration , endPointCustomization ) ;
22
+ }
23
+
18
24
/// <summary>
19
25
/// Get a <see cref="T:Splunk.Loggers.HECJsonLogger"/> instance to the category name provided.
20
26
/// </summary>
@@ -33,14 +39,7 @@ public abstract class SplunkHECBaseProvider : ILoggerProvider
33
39
/// that the <see cref="T:Splunk.Providers.SplunkHECJsonLoggerProvider"/> was occupying.</remarks>
34
40
public abstract void Dispose ( ) ;
35
41
36
- /// <summary>
37
- /// Create a <see cref="T:Splunk.Loggers.HECJsonLogger"/> instance to the category name provided.
38
- /// </summary>
39
- /// <returns>The logger instance.</returns>
40
- /// <param name="categoryName">Category name.</param>
41
- public abstract ILogger CreateLoggerInstance ( string categoryName ) ;
42
-
43
- protected void SetupHttpClient ( SplunkLoggerConfiguration configuration , string endPointCustomization )
42
+ void SetupHttpClient ( SplunkLoggerConfiguration configuration , string endPointCustomization )
44
43
{
45
44
httpClient = new HttpClient
46
45
{
@@ -55,69 +54,69 @@ protected void SetupHttpClient(SplunkLoggerConfiguration configuration, string e
55
54
httpClient . DefaultRequestHeaders . Add ( "x-splunk-request-channel" , Guid . NewGuid ( ) . ToString ( ) ) ;
56
55
}
57
56
58
- Uri GetSplunkCollectorUrl ( SplunkLoggerConfiguration configuration , string endPointCustomization )
59
- {
60
- var splunkCollectorUrl = configuration . HecConfiguration . SplunkCollectorUrl ;
61
- if ( ! splunkCollectorUrl . EndsWith ( "/" , StringComparison . InvariantCulture ) )
62
- splunkCollectorUrl = splunkCollectorUrl + "/" ;
63
-
64
- if ( ! string . IsNullOrWhiteSpace ( endPointCustomization ) )
65
- splunkCollectorUrl = splunkCollectorUrl + endPointCustomization ;
66
-
67
- if ( configuration . HecConfiguration . ChannelIdType == HECConfiguration . ChannelIdOption . QueryString )
68
- splunkCollectorUrl = splunkCollectorUrl + "?channel=" + Guid . NewGuid ( ) . ToString ( ) ;
69
-
70
- if ( configuration . HecConfiguration . UseAuthTokenAsQueryString )
71
- {
72
- var tokenParameter = "token=" + configuration . HecConfiguration . Token ;
73
- splunkCollectorUrl = string . Format ( "{0}{1}{2}" , splunkCollectorUrl , splunkCollectorUrl . Contains ( "?" ) ? "&" : "?" , tokenParameter ) ;
74
- }
75
-
76
- return new Uri ( splunkCollectorUrl ) ;
77
- }
78
-
79
57
protected void DebugSplunkResponse ( Task < HttpResponseMessage > responseMessageTask , string loggerType )
80
58
{
81
59
if ( responseMessageTask . IsCompletedSuccessfully )
82
- {
60
+ {
83
61
switch ( responseMessageTask . Result . StatusCode )
84
62
{
85
63
case System . Net . HttpStatusCode . OK :
86
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Request completed successfully.") ;
64
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Request completed successfully.") ;
87
65
break ;
88
66
case System . Net . HttpStatusCode . Created :
89
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Create request completed successfully.") ;
67
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Create request completed successfully.") ;
90
68
break ;
91
69
case System . Net . HttpStatusCode . BadRequest :
92
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Request error. See response body for details.") ;
70
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Request error. See response body for details.") ;
93
71
break ;
94
72
case System . Net . HttpStatusCode . Unauthorized :
95
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Authentication failure, invalid access credentials.") ;
73
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Authentication failure, invalid access credentials.") ;
96
74
break ;
97
75
case System . Net . HttpStatusCode . PaymentRequired :
98
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: In-use Splunk Enterprise license disables this feature.") ;
76
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: In-use Splunk Enterprise license disables this feature.") ;
99
77
break ;
100
78
case System . Net . HttpStatusCode . Forbidden :
101
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Insufficient permission.") ;
79
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Insufficient permission.") ;
102
80
break ;
103
81
case System . Net . HttpStatusCode . NotFound :
104
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Requested endpoint does not exist.") ;
82
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Requested endpoint does not exist.") ;
105
83
break ;
106
84
case System . Net . HttpStatusCode . Conflict :
107
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Invalid operation for this endpoint. See response body for details.") ;
85
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Invalid operation for this endpoint. See response body for details.") ;
108
86
break ;
109
87
case System . Net . HttpStatusCode . InternalServerError :
110
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Unspecified internal server error. See response body for details.") ;
88
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Unspecified internal server error. See response body for details.") ;
111
89
break ;
112
90
case System . Net . HttpStatusCode . ServiceUnavailable :
113
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Feature is disabled in configuration file.") ;
91
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Feature is disabled in configuration file.") ;
114
92
break ;
115
- }
93
+ }
116
94
}
117
95
else if ( responseMessageTask . IsCanceled )
118
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Canceled") ;
96
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Canceled") ;
119
97
else
120
- Debug . WriteLine ( $ "Splunk HEC { loggerType } Status: Error " + responseMessageTask . Exception != null ? responseMessageTask . Exception . ToString ( ) : "" ) ;
98
+ Debug . WriteLine ( $ "[DEBUG] Splunk HEC { loggerType } Status: Error " + responseMessageTask . Exception != null ? responseMessageTask . Exception . ToString ( ) : "" ) ;
99
+ }
100
+
101
+ Uri GetSplunkCollectorUrl ( SplunkLoggerConfiguration configuration , string endPointCustomization )
102
+ {
103
+ var splunkCollectorUrl = configuration . HecConfiguration . SplunkCollectorUrl ;
104
+ if ( ! splunkCollectorUrl . EndsWith ( "/" , StringComparison . InvariantCulture ) )
105
+ splunkCollectorUrl = splunkCollectorUrl + "/" ;
106
+
107
+ if ( ! string . IsNullOrWhiteSpace ( endPointCustomization ) )
108
+ splunkCollectorUrl = splunkCollectorUrl + endPointCustomization ;
109
+
110
+ if ( configuration . HecConfiguration . ChannelIdType == HECConfiguration . ChannelIdOption . QueryString )
111
+ splunkCollectorUrl = splunkCollectorUrl + "?channel=" + Guid . NewGuid ( ) . ToString ( ) ;
112
+
113
+ if ( configuration . HecConfiguration . UseAuthTokenAsQueryString )
114
+ {
115
+ var tokenParameter = "token=" + configuration . HecConfiguration . Token ;
116
+ splunkCollectorUrl = string . Format ( "{0}{1}{2}" , splunkCollectorUrl , splunkCollectorUrl . Contains ( "?" ) ? "&" : "?" , tokenParameter ) ;
117
+ }
118
+
119
+ return new Uri ( splunkCollectorUrl ) ;
121
120
}
122
121
}
123
122
}
0 commit comments