14
14
15
15
16
16
using System ;
17
- using System . Runtime . CompilerServices ;
17
+ using System . Net . Http ;
18
18
using Serilog . Configuration ;
19
19
using Serilog . Events ;
20
20
using Serilog . Sinks . Splunk ;
21
21
22
22
namespace Serilog
23
23
{
24
24
/// <summary>
25
- /// Fluent configuration methods for Logger configuration
25
+ /// Fluent configuration methods for Logger configuration
26
26
/// </summary>
27
27
public static class SplunkLoggingConfigurationExtensions
28
- {
28
+ {
29
+ internal const string DefaultOutputTemplate =
30
+ "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}" ;
29
31
30
- internal const string DefaultOutputTemplate =
31
- "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}" ;
32
+ /// <summary>
33
+ /// Adds a sink that writes log events as to a Splunk instance via the HTTP Event Collector.
34
+ /// </summary>
35
+ /// <param name="configuration">The logger config</param>
36
+ /// <param name="splunkHost">The Splunk host that is configured with an Event Collector</param>
37
+ /// <param name="eventCollectorToken">The token provided to authenticate to the Splunk Event Collector</param>
38
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
39
+ /// <param name="outputTemplate">The output template to be used when logging</param>
40
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
41
+ /// <param name="renderTemplate">If ture, the message template will be rendered</param>
42
+ /// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
43
+ /// <param name="batchSizeLimit">The size of the batch</param>
44
+ /// <returns></returns>
45
+ public static LoggerConfiguration EventCollector (
46
+ this LoggerSinkConfiguration configuration ,
47
+ string splunkHost ,
48
+ string eventCollectorToken ,
49
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
50
+ string outputTemplate = DefaultOutputTemplate ,
51
+ IFormatProvider formatProvider = null ,
52
+ bool renderTemplate = true ,
53
+ int batchIntervalInSeconds = 2 ,
54
+ int batchSizeLimit = 100 )
55
+ {
56
+ if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
57
+ if ( outputTemplate == null ) throw new ArgumentNullException ( nameof ( outputTemplate ) ) ;
32
58
33
- /// <summary>
34
- /// Adds a sink that writes log events as to a Splunk instance via the HTTP Event Collector.
35
- /// </summary>
36
- /// <param name="configuration">The logger config</param>
37
- /// <param name="splunkHost">The Splunk host that is configured with an Event Collector</param>
38
- /// <param name="eventCollectorToken">The token provided to authenticate to the Splunk Event Collector</param>
39
- /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
40
- /// <param name="outputTemplate">The output template to be used when logging</param>
41
- /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
42
- /// <param name="renderTemplate">If ture, the message template will be rendered</param>
43
- /// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
44
- /// <param name="batchSizeLimit">The size of the batch</param>
45
- /// <returns></returns>
46
- public static LoggerConfiguration EventCollector (
47
- this LoggerSinkConfiguration configuration ,
48
- string splunkHost ,
49
- string eventCollectorToken ,
50
- LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
51
- string outputTemplate = DefaultOutputTemplate ,
52
- IFormatProvider formatProvider = null ,
53
- bool renderTemplate = true ,
54
- int batchIntervalInSeconds = 2 ,
55
- int batchSizeLimit = 100 )
56
- {
57
- if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
58
- if ( outputTemplate == null ) throw new ArgumentNullException ( nameof ( outputTemplate ) ) ;
59
+ var eventCollectorSink = new EventCollectorSink (
60
+ splunkHost ,
61
+ eventCollectorToken ,
62
+ batchIntervalInSeconds ,
63
+ batchSizeLimit ,
64
+ formatProvider ,
65
+ renderTemplate ) ;
59
66
60
- var eventCollectorSink = new EventCollectorSink (
61
- splunkHost ,
62
- eventCollectorToken ,
63
- batchIntervalInSeconds ,
64
- batchSizeLimit ,
65
- formatProvider ,
66
- renderTemplate ) ;
67
-
68
- return configuration . Sink ( eventCollectorSink , restrictedToMinimumLevel ) ;
69
- }
70
-
71
-
72
- /// <summary>
73
- /// Adds a sink that writes log events as to a Splunk instance via the HTTP Event Collector.
74
- /// </summary>
75
- /// <param name="configuration">The logger config</param>
76
- /// <param name="splunkHost">The Splunk host that is configured with an Event Collector</param>
77
- /// <param name="eventCollectorToken">The token provided to authenticate to the Splunk Event Collector</param>
78
- /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
79
- /// <param name="outputTemplate">The output template to be used when logging</param>
80
- /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
81
- /// <param name="renderTemplate">If ture, the message template will be rendered</param>
82
- /// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
83
- /// <param name="batchSizeLimit">The size of the batch</param>
84
- /// <returns></returns>
85
- public static LoggerConfiguration SplunkViaEventCollector (
86
- this LoggerSinkConfiguration configuration ,
87
- string splunkHost ,
88
- string eventCollectorToken ,
89
- LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
90
- string outputTemplate = DefaultOutputTemplate ,
91
- IFormatProvider formatProvider = null ,
92
- bool renderTemplate = true ,
93
- int batchIntervalInSeconds = 2 ,
94
- int batchSizeLimit = 100 )
95
- {
96
- return EventCollector ( configuration , splunkHost , eventCollectorToken , restrictedToMinimumLevel ,
97
- outputTemplate , formatProvider , renderTemplate , batchIntervalInSeconds , batchSizeLimit ) ;
98
- }
67
+ return configuration . Sink ( eventCollectorSink , restrictedToMinimumLevel ) ;
68
+ }
99
69
70
+ /// <summary>
71
+ /// Adds a sink that writes log events as to a Splunk instance via the HTTP Event Collector.
72
+ /// </summary>
73
+ /// <param name="configuration">The logger config</param>
74
+ /// <param name="splunkHost">The Splunk host that is configured with an Event Collector</param>
75
+ /// <param name="eventCollectorToken">The token provided to authenticate to the Splunk Event Collector</param>
76
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
77
+ /// <param name="outputTemplate">The output template to be used when logging</param>
78
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
79
+ /// <param name="renderTemplate">If ture, the message template will be rendered</param>
80
+ /// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
81
+ /// <param name="batchSizeLimit">The size of the batch</param>
82
+ /// <returns></returns>
83
+ public static LoggerConfiguration SplunkViaEventCollector (
84
+ this LoggerSinkConfiguration configuration ,
85
+ string splunkHost ,
86
+ string eventCollectorToken ,
87
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
88
+ string outputTemplate = DefaultOutputTemplate ,
89
+ IFormatProvider formatProvider = null ,
90
+ bool renderTemplate = true ,
91
+ int batchIntervalInSeconds = 2 ,
92
+ int batchSizeLimit = 100 )
93
+ {
94
+ return EventCollector ( configuration , splunkHost , eventCollectorToken , restrictedToMinimumLevel ,
95
+ outputTemplate , formatProvider , renderTemplate , batchIntervalInSeconds , batchSizeLimit ) ;
100
96
}
97
+ }
101
98
}
0 commit comments