16
16
using System . Net ;
17
17
using Serilog . Configuration ;
18
18
using Serilog . Events ;
19
+ using Serilog . Formatting ;
19
20
using Serilog . Formatting . Display ;
20
21
using Serilog . Sinks . Splunk ;
21
22
@@ -26,6 +27,46 @@ namespace Serilog
26
27
/// </summary>
27
28
public static class LoggerConfigurationSplunkExtensions
28
29
{
30
+ /// <summary>
31
+ /// Adds a sink that writes log events as to a Splunk instance via UDP.
32
+ /// </summary>
33
+ /// <param name="loggerConfiguration">The logger config</param>
34
+ /// <param name="connectionInfo"></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="renderTemplate">If true, the message template is rendered</param>
38
+ /// <returns></returns>
39
+ public static LoggerConfiguration SplunkViaUdp (
40
+ this LoggerSinkConfiguration loggerConfiguration ,
41
+ SplunkUdpSinkConnectionInfo connectionInfo ,
42
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
43
+ IFormatProvider formatProvider = null ,
44
+ bool renderTemplate = true )
45
+ {
46
+ var sink = new UdpSink ( connectionInfo , formatProvider , renderTemplate ) ;
47
+
48
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
49
+ }
50
+
51
+ /// <summary>
52
+ /// Adds a sink that writes log events as to a Splunk instance via UDP.
53
+ /// </summary>
54
+ /// <param name="loggerConfiguration">The logger config</param>
55
+ /// <param name="connectionInfo"></param>
56
+ /// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
57
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
58
+ /// <returns></returns>
59
+ public static LoggerConfiguration SplunkViaUdp (
60
+ this LoggerSinkConfiguration loggerConfiguration ,
61
+ SplunkUdpSinkConnectionInfo connectionInfo ,
62
+ ITextFormatter formatter ,
63
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum )
64
+ {
65
+ var sink = new UdpSink ( connectionInfo , formatter ) ;
66
+
67
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
68
+ }
69
+
29
70
/// <summary>
30
71
/// Adds a sink that writes log events as to a Splunk instance via UDP.
31
72
/// </summary>
@@ -37,6 +78,7 @@ public static class LoggerConfigurationSplunkExtensions
37
78
/// <param name="renderTemplate">If ture, the message template will be rendered</param>
38
79
/// <returns></returns>
39
80
/// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
81
+ [ Obsolete ( "Use the overload accepting a connection info object instead. This overload will be removed." , false ) ]
40
82
public static LoggerConfiguration SplunkViaUdp (
41
83
this LoggerSinkConfiguration loggerConfiguration ,
42
84
string host ,
@@ -62,6 +104,7 @@ public static LoggerConfiguration SplunkViaUdp(
62
104
/// <param name="renderTemplate">If ture, the message template is rendered</param>
63
105
/// <returns>The logger configuration</returns>
64
106
/// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
107
+ [ Obsolete ( "Use the overload accepting a connection info object instead. This overload will be removed." , false ) ]
65
108
public static LoggerConfiguration SplunkViaUdp (
66
109
this LoggerSinkConfiguration loggerConfiguration ,
67
110
IPAddress hostAddresss ,
@@ -75,6 +118,46 @@ public static LoggerConfiguration SplunkViaUdp(
75
118
return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
76
119
}
77
120
121
+ /// <summary>
122
+ /// Adds a sink that writes log events as to a Splunk instance via TCP.
123
+ /// </summary>
124
+ /// <param name="loggerConfiguration">The logger config</param>
125
+ /// <param name="connectionInfo"></param>
126
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
127
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
128
+ /// <param name="renderTemplate">If true, the message template is rendered</param>
129
+ /// <returns></returns>
130
+ public static LoggerConfiguration SplunkViaTcp (
131
+ this LoggerSinkConfiguration loggerConfiguration ,
132
+ SplunkTcpSinkConnectionInfo connectionInfo ,
133
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
134
+ IFormatProvider formatProvider = null ,
135
+ bool renderTemplate = true )
136
+ {
137
+ var sink = new TcpSink ( connectionInfo , formatProvider , renderTemplate ) ;
138
+
139
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
140
+ }
141
+
142
+ /// <summary>
143
+ /// Adds a sink that writes log events as to a Splunk instance via TCP.
144
+ /// </summary>
145
+ /// <param name="loggerConfiguration">The logger config</param>
146
+ /// <param name="connectionInfo"></param>
147
+ /// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
148
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
149
+ /// <returns></returns>
150
+ public static LoggerConfiguration SplunkViaTcp (
151
+ this LoggerSinkConfiguration loggerConfiguration ,
152
+ SplunkTcpSinkConnectionInfo connectionInfo ,
153
+ ITextFormatter formatter ,
154
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum )
155
+ {
156
+ var sink = new TcpSink ( connectionInfo , formatter ) ;
157
+
158
+ return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
159
+ }
160
+
78
161
/// <summary>
79
162
/// Adds a sink that writes log events as to a Splunk instance via TCP.
80
163
/// </summary>
@@ -86,6 +169,7 @@ public static LoggerConfiguration SplunkViaUdp(
86
169
/// <param name="renderTemplate">If true, the message template is rendered</param>
87
170
/// <returns></returns>
88
171
/// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
172
+ [ Obsolete ( "Use the overload accepting a connection info object instead. This overload will be removed." , false ) ]
89
173
public static LoggerConfiguration SplunkViaTcp (
90
174
this LoggerSinkConfiguration loggerConfiguration ,
91
175
IPAddress hostAddresss ,
@@ -110,6 +194,7 @@ public static LoggerConfiguration SplunkViaTcp(
110
194
/// <param name="renderTemplate">If ture, the message template is rendered</param>
111
195
/// <returns></returns>
112
196
/// <remarks>TODO: Add link to splunk configuration and wiki</remarks>
197
+ [ Obsolete ( "Use the overload accepting a connection info object instead. This overload will be removed." , false ) ]
113
198
public static LoggerConfiguration SplunkViaTcp (
114
199
this LoggerSinkConfiguration loggerConfiguration ,
115
200
string host ,
@@ -122,6 +207,5 @@ public static LoggerConfiguration SplunkViaTcp(
122
207
123
208
return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
124
209
}
125
-
126
210
}
127
211
}
0 commit comments