1616using System . Net ;
1717using Serilog . Configuration ;
1818using Serilog . Events ;
19+ using Serilog . Formatting ;
1920using Serilog . Formatting . Display ;
2021using Serilog . Sinks . Splunk ;
2122
@@ -26,6 +27,46 @@ namespace Serilog
2627 /// </summary>
2728 public static class LoggerConfigurationSplunkExtensions
2829 {
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+
2970 /// <summary>
3071 /// Adds a sink that writes log events as to a Splunk instance via UDP.
3172 /// </summary>
@@ -37,6 +78,7 @@ public static class LoggerConfigurationSplunkExtensions
3778 /// <param name="renderTemplate">If ture, the message template will be rendered</param>
3879 /// <returns></returns>
3980 /// <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 ) ]
4082 public static LoggerConfiguration SplunkViaUdp (
4183 this LoggerSinkConfiguration loggerConfiguration ,
4284 string host ,
@@ -62,6 +104,7 @@ public static LoggerConfiguration SplunkViaUdp(
62104 /// <param name="renderTemplate">If ture, the message template is rendered</param>
63105 /// <returns>The logger configuration</returns>
64106 /// <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 ) ]
65108 public static LoggerConfiguration SplunkViaUdp (
66109 this LoggerSinkConfiguration loggerConfiguration ,
67110 IPAddress hostAddresss ,
@@ -75,6 +118,46 @@ public static LoggerConfiguration SplunkViaUdp(
75118 return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
76119 }
77120
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+
78161 /// <summary>
79162 /// Adds a sink that writes log events as to a Splunk instance via TCP.
80163 /// </summary>
@@ -86,6 +169,7 @@ public static LoggerConfiguration SplunkViaUdp(
86169 /// <param name="renderTemplate">If true, the message template is rendered</param>
87170 /// <returns></returns>
88171 /// <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 ) ]
89173 public static LoggerConfiguration SplunkViaTcp (
90174 this LoggerSinkConfiguration loggerConfiguration ,
91175 IPAddress hostAddresss ,
@@ -110,6 +194,7 @@ public static LoggerConfiguration SplunkViaTcp(
110194 /// <param name="renderTemplate">If ture, the message template is rendered</param>
111195 /// <returns></returns>
112196 /// <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 ) ]
113198 public static LoggerConfiguration SplunkViaTcp (
114199 this LoggerSinkConfiguration loggerConfiguration ,
115200 string host ,
@@ -122,6 +207,5 @@ public static LoggerConfiguration SplunkViaTcp(
122207
123208 return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
124209 }
125-
126210 }
127211}
0 commit comments