@@ -32,57 +32,75 @@ public class TcpSink : ILogEventSink, IDisposable
3232 private TcpSocketWriter _writer ;
3333
3434 /// <summary>
35- /// Creates an instance of the Splunk TCP Sink
35+ /// Creates an instance of the Splunk TCP Sink.
3636 /// </summary>
37- /// <param name="host">The Splunk Host</param>
38- /// <param name="port">The UDP port configured in Splunk</param>
37+ /// <param name="connectionInfo">Connection info used for connecting against Splunk.</param>
3938 /// <param name="formatProvider">Optional format provider</param>
4039 /// <param name="renderTemplate">If true, the message template will be rendered</param>
4140 public TcpSink (
42- string host ,
43- int port ,
41+ SplunkTcpSinkConnectionInfo connectionInfo ,
4442 IFormatProvider formatProvider = null ,
45- bool renderTemplate = true ) : this ( IPAddress . Parse ( host ) , port , formatProvider , renderTemplate )
43+ bool renderTemplate = true )
4644 {
45+ _writer = CreateSocketWriter ( connectionInfo ) ;
46+ _formatter = CreateDefaultFormatter ( formatProvider , renderTemplate ) ;
47+ }
48+
49+ /// <summary>
50+ /// Creates an instance of the Splunk TCP Sink.
51+ /// </summary>
52+ /// <param name="connectionInfo">Connection info used for connecting against Splunk.</param>
53+ /// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
54+ public TcpSink (
55+ SplunkTcpSinkConnectionInfo connectionInfo ,
56+ ITextFormatter formatter )
57+ {
58+ _writer = CreateSocketWriter ( connectionInfo ) ;
59+ _formatter = formatter ;
4760 }
4861
4962 /// <summary>
5063 /// Creates an instance of the Splunk TCP Sink
5164 /// </summary>
52- /// <param name="hostAddress ">The Splunk Host</param>
53- /// <param name="port">The UDP port configured in Splunk</param>
65+ /// <param name="host ">The Splunk Host</param>
66+ /// <param name="port">The TCP port configured in Splunk</param>
5467 /// <param name="formatProvider">Optional format provider</param>
5568 /// <param name="renderTemplate">If true, the message template will be rendered</param>
69+ [ Obsolete ( "Use the overload accepting a connection info object instead. This overload will be removed." , false ) ]
5670 public TcpSink (
57- IPAddress hostAddress ,
71+ string host ,
5872 int port ,
5973 IFormatProvider formatProvider = null ,
60- bool renderTemplate = true )
74+ bool renderTemplate = true ) : this ( new SplunkTcpSinkConnectionInfo ( host , port ) , formatProvider , renderTemplate )
6175 {
62- _writer = CreateSocketWriter ( hostAddress , port ) ;
63- _formatter = new SplunkJsonFormatter ( renderMessage : true , formatProvider : formatProvider , renderTemplate : renderTemplate ) ;
6476 }
6577
6678 /// <summary>
67- /// Creates an instance of the Splunk TCP sink.
79+ /// Creates an instance of the Splunk TCP Sink
6880 /// </summary>
69- /// <param name="host">The Splunk Host</param>
70- /// <param name="port">The UDP port configured in Splunk</param>
71- /// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
81+ /// <param name="hostAddress">The Splunk Host</param>
82+ /// <param name="port">The TCP port configured in Splunk</param>
83+ /// <param name="formatProvider">Optional format provider</param>
84+ /// <param name="renderTemplate">If true, the message template will be rendered</param>
85+ [ Obsolete ( "Use the overload accepting a connection info object instead. This overload will be removed." , false ) ]
7286 public TcpSink (
73- string host ,
87+ IPAddress hostAddress ,
7488 int port ,
75- ITextFormatter formatter )
89+ IFormatProvider formatProvider = null ,
90+ bool renderTemplate = true ) : this ( new SplunkTcpSinkConnectionInfo ( hostAddress , port ) , formatProvider , renderTemplate )
7691 {
77- _writer = CreateSocketWriter ( IPAddress . Parse ( host ) , port ) ;
78- _formatter = formatter ;
7992 }
8093
81- private static TcpSocketWriter CreateSocketWriter ( IPAddress hostAddress , int port )
94+ private static TcpSocketWriter CreateSocketWriter ( SplunkTcpSinkConnectionInfo connectionInfo )
8295 {
8396 var reconnectionPolicy = new ExponentialBackoffTcpReconnectionPolicy ( ) ;
8497
85- return new TcpSocketWriter ( hostAddress , port , reconnectionPolicy , 10000 ) ;
98+ return new TcpSocketWriter ( connectionInfo . Host , connectionInfo . Port , reconnectionPolicy , connectionInfo . MaxQueueSize ) ;
99+ }
100+
101+ private static SplunkJsonFormatter CreateDefaultFormatter ( IFormatProvider formatProvider , bool renderTemplate )
102+ {
103+ return new SplunkJsonFormatter ( renderMessage : true , formatProvider : formatProvider , renderTemplate : renderTemplate ) ;
86104 }
87105
88106 /// <inheritdoc/>
@@ -103,5 +121,4 @@ public void Dispose()
103121 _writer = null ;
104122 }
105123 }
106- }
107-
124+ }
0 commit comments