1
+ // Copyright 2014 Serilog Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ using System ;
16
+ using System . Net ;
17
+ using Serilog . Configuration ;
18
+ using Serilog . Events ;
19
+ using Serilog . Sinks . Splunk ;
20
+ using Splunk . Client ;
21
+
22
+ namespace Serilog
23
+ {
24
+ /// <summary>
25
+ /// Adds the WriteTo.SplunkViaHttp() extension method to <see cref="LoggerConfiguration"/>.
26
+ /// </summary>
27
+ public static class LoggerConfigurationSplunkExtensions
28
+ {
29
+ /// <summary>
30
+ /// Adds a sink that writes log events as to a Splunk instance via http.
31
+ /// </summary>
32
+ /// <param name="loggerConfiguration">The logger configuration.</param>
33
+ /// <param name="context">The Splunk context to log to</param>
34
+ /// <param name="batchInterval"></param>
35
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
36
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
37
+ /// <param name="batchSizeLimit"></param>
38
+ /// <returns>Logger configuration, allowing configuration to continue.</returns>
39
+ /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
40
+ /// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
41
+ public static LoggerConfiguration SplunkViaHttp (
42
+ this LoggerSinkConfiguration loggerConfiguration ,
43
+ SplunkContext context ,
44
+ int batchSizeLimit ,
45
+ TimeSpan batchInterval ,
46
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
47
+ IFormatProvider formatProvider = null )
48
+ {
49
+ var sink = new SplunkViaHttpSink ( context , batchSizeLimit , batchInterval , formatProvider ) ;
50
+
51
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
52
+ }
53
+
54
+ /// <summary>
55
+ /// Adds a sink that writes log events as to a Splunk instance via http.
56
+ /// </summary>
57
+ /// <param name="loggerConfiguration">The logger configuration.</param>
58
+ /// <param name="context">The Splunk context to log to</param>
59
+ /// <param name="password"></param>
60
+ /// <param name="resourceNameSpace"></param>
61
+ /// <param name="transmitterArgs"></param>
62
+ /// <param name="batchSizeLimit">The size of the batch prior to logging</param>
63
+ /// <param name="batchInterval">The interval on which to log via http</param>
64
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
65
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
66
+ /// <param name="index"></param>
67
+ /// <param name="userName"></param>
68
+ /// <returns>Logger configuration, allowing configuration to continue.</returns>
69
+ /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
70
+ /// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
71
+ public static LoggerConfiguration SplunkViaHttp (
72
+ this LoggerSinkConfiguration loggerConfiguration ,
73
+ Splunk . Client . Context context ,
74
+ string index ,
75
+ string userName ,
76
+ string password ,
77
+ int batchSizeLimit ,
78
+ TimeSpan batchInterval ,
79
+ Namespace resourceNameSpace ,
80
+ TransmitterArgs transmitterArgs ,
81
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
82
+ IFormatProvider formatProvider = null )
83
+ {
84
+ var sink = new SplunkViaHttpSink ( new SplunkContext ( context , index , userName , password , resourceNameSpace , transmitterArgs ) , batchSizeLimit , batchInterval , formatProvider ) ;
85
+
86
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
87
+ }
88
+
89
+ /// <summary>
90
+ /// Adds a sink that writes log events as to a Splunk instance via http.
91
+ /// </summary>
92
+ /// <param name="loggerConfiguration">The logger config</param>
93
+ /// <param name="host">The Splunk host that is configured for UDP logging</param>
94
+ /// <param name="port">The UDP port</param>
95
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
96
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
97
+ /// <returns></returns>
98
+ /// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
99
+ public static LoggerConfiguration SplunkViaUdp (
100
+ this LoggerSinkConfiguration loggerConfiguration ,
101
+ string host ,
102
+ int port ,
103
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
104
+ IFormatProvider formatProvider = null )
105
+ {
106
+ var sink = new SplunkViaUdpSink ( host , port , formatProvider ) ;
107
+
108
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
109
+ }
110
+
111
+
112
+ /// <summary>
113
+ /// Adds a sink that writes log events as to a Splunk instance via UDP.
114
+ /// </summary>
115
+ /// <param name="loggerConfiguration">The logger config</param>
116
+ /// <param name="hostAddresss">The Splunk host that is configured for UDP logging</param>
117
+ /// <param name="port">The UDP port</param>
118
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
119
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
120
+ /// <returns></returns>
121
+ /// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
122
+ public static LoggerConfiguration SplunkViaUdp (
123
+ this LoggerSinkConfiguration loggerConfiguration ,
124
+ IPAddress hostAddresss ,
125
+ int port ,
126
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
127
+ IFormatProvider formatProvider = null )
128
+ {
129
+ var sink = new SplunkViaUdpSink ( hostAddresss , port , formatProvider ) ;
130
+
131
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
132
+ }
133
+
134
+ /// <summary>
135
+ /// Adds a sink that writes log events as to a Splunk instance via TCP.
136
+ /// </summary>
137
+ /// <param name="loggerConfiguration">The logger config</param>
138
+ /// <param name="hostAddresss">The Splunk host that is configured for UDP logging</param>
139
+ /// <param name="port">The TCP port</param>
140
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
141
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
142
+ /// <returns></returns>
143
+ /// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
144
+ public static LoggerConfiguration SplunkViaTcp (
145
+ this LoggerSinkConfiguration loggerConfiguration ,
146
+ IPAddress hostAddresss ,
147
+ int port ,
148
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
149
+ IFormatProvider formatProvider = null )
150
+ {
151
+ var sink = new SplunkViaTcpSink ( hostAddresss , port , formatProvider ) ;
152
+
153
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
154
+ }
155
+
156
+ /// <summary>
157
+ /// Adds a sink that writes log events as to a Splunk instance via TCP.
158
+ /// </summary>
159
+ /// <param name="loggerConfiguration">The logger config</param>
160
+ /// <param name="host">The Splunk host that is configured for UDP logging</param>
161
+ /// <param name="port">The TCP port</param>
162
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
163
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
164
+ /// <returns></returns>
165
+ /// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
166
+ public static LoggerConfiguration SplunkViaTcp (
167
+ this LoggerSinkConfiguration loggerConfiguration ,
168
+ string host ,
169
+ int port ,
170
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
171
+ IFormatProvider formatProvider = null )
172
+ {
173
+ var sink = new SplunkViaTcpSink ( host , port , formatProvider ) ;
174
+
175
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
176
+ }
177
+
178
+ }
179
+ }
0 commit comments