-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSyslogEventSink.cs
More file actions
94 lines (86 loc) · 2.98 KB
/
SyslogEventSink.cs
File metadata and controls
94 lines (86 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Waher.Security;
namespace Waher.Events.Syslog
{
/// <summary>
/// Event sink that sends events to a Syslog server using the Syslog protocol.
/// </summary>
public class SyslogEventSink : EventSink, ITlsCertificateEndpoint
{
private SyslogClient client;
/// <summary>
/// Event sink that sends events to a Syslog server using the Syslog protocol.
/// </summary>
/// <param name="Host">Syslog server to send events to.</param>
/// <param name="Port">Syslog server port number to use.</param>
/// <param name="Tls">If TLS is to be used.</param>
/// <param name="LocalHostName">Local host name</param>
/// <param name="AppName">Application name</param>
/// <param name="Separation">How events are separated in the event stream.</param>
/// <param name="ObjectID">Object ID</param>
public SyslogEventSink(string Host, int Port, bool Tls, string LocalHostName,
string AppName, SyslogEventSeparation Separation, string ObjectID)
: base(ObjectID)
{
this.client = new SyslogClient(Host, Port, Tls, LocalHostName, AppName, Separation);
}
/// <summary>
/// Event sink that sends events to a Syslog server using the Syslog protocol.
/// </summary>
/// <param name="Host">Syslog server to send events to.</param>
/// <param name="Port">Syslog server port number to use.</param>
/// <param name="Certificate">Client certificate for use with mTLS.</param>
/// <param name="LocalHostName">Local host name</param>
/// <param name="AppName">Application name</param>
/// <param name="Separation">How events are separated in the event stream.</param>
/// <param name="ObjectID">Object ID</param>
public SyslogEventSink(string Host, int Port, X509Certificate Certificate,
string LocalHostName, string AppName, SyslogEventSeparation Separation,
string ObjectID)
: base(ObjectID)
{
this.client = new SyslogClient(Host, Port, Certificate, LocalHostName, AppName, Separation);
}
/// <summary>
/// Queues an event to be output.
/// </summary>
/// <param name="Event">Event to queue.</param>
public override async Task Queue(Event Event)
{
try
{
await this.client.Send(Event);
}
catch (Exception ex)
{
Event Event2 = new Event(EventType.Critical, ex, this.ObjectID,
string.Empty, string.Empty, EventLevel.Medium, string.Empty,
string.Empty);
Event2.Avoid(this);
Log.Event(Event2);
}
}
/// <summary>
/// <see cref="IDisposableAsync.DisposeAsync()"/>
/// </summary>
public override async Task DisposeAsync()
{
if (!(this.client is null))
{
await this.client.DisposeAsync();
this.client = null;
}
await base.DisposeAsync();
}
/// <summary>
/// Updates the certificate used in mTLS negotiation.
/// </summary>
/// <param name="Certificate">Updated Certificate</param>
public void UpdateCertificate(X509Certificate Certificate)
{
this.client.UpdateCertificate(Certificate);
}
}
}