@@ -32,57 +32,75 @@ public class TcpSink : ILogEventSink, IDisposable
32
32
private TcpSocketWriter _writer ;
33
33
34
34
/// <summary>
35
- /// Creates an instance of the Splunk TCP Sink
35
+ /// Creates an instance of the Splunk TCP Sink.
36
36
/// </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>
39
38
/// <param name="formatProvider">Optional format provider</param>
40
39
/// <param name="renderTemplate">If true, the message template will be rendered</param>
41
40
public TcpSink (
42
- string host ,
43
- int port ,
41
+ SplunkTcpSinkConnectionInfo connectionInfo ,
44
42
IFormatProvider formatProvider = null ,
45
- bool renderTemplate = true ) : this ( IPAddress . Parse ( host ) , port , formatProvider , renderTemplate )
43
+ bool renderTemplate = true )
46
44
{
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 ;
47
60
}
48
61
49
62
/// <summary>
50
63
/// Creates an instance of the Splunk TCP Sink
51
64
/// </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>
54
67
/// <param name="formatProvider">Optional format provider</param>
55
68
/// <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 ) ]
56
70
public TcpSink (
57
- IPAddress hostAddress ,
71
+ string host ,
58
72
int port ,
59
73
IFormatProvider formatProvider = null ,
60
- bool renderTemplate = true )
74
+ bool renderTemplate = true ) : this ( new SplunkTcpSinkConnectionInfo ( host , port ) , formatProvider , renderTemplate )
61
75
{
62
- _writer = CreateSocketWriter ( hostAddress , port ) ;
63
- _formatter = new SplunkJsonFormatter ( renderMessage : true , formatProvider : formatProvider , renderTemplate : renderTemplate ) ;
64
76
}
65
77
66
78
/// <summary>
67
- /// Creates an instance of the Splunk TCP sink.
79
+ /// Creates an instance of the Splunk TCP Sink
68
80
/// </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 ) ]
72
86
public TcpSink (
73
- string host ,
87
+ IPAddress hostAddress ,
74
88
int port ,
75
- ITextFormatter formatter )
89
+ IFormatProvider formatProvider = null ,
90
+ bool renderTemplate = true ) : this ( new SplunkTcpSinkConnectionInfo ( hostAddress , port ) , formatProvider , renderTemplate )
76
91
{
77
- _writer = CreateSocketWriter ( IPAddress . Parse ( host ) , port ) ;
78
- _formatter = formatter ;
79
92
}
80
93
81
- private static TcpSocketWriter CreateSocketWriter ( IPAddress hostAddress , int port )
94
+ private static TcpSocketWriter CreateSocketWriter ( SplunkTcpSinkConnectionInfo connectionInfo )
82
95
{
83
96
var reconnectionPolicy = new ExponentialBackoffTcpReconnectionPolicy ( ) ;
84
97
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 ) ;
86
104
}
87
105
88
106
/// <inheritdoc/>
@@ -103,5 +121,4 @@ public void Dispose()
103
121
_writer = null ;
104
122
}
105
123
}
106
- }
107
-
124
+ }
0 commit comments