91 lines
2.0 KiB
C#
91 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
|
|
namespace EonaCat.Logger.Syslog
|
|
{
|
|
/// <summary>
|
|
/// Syslog server.
|
|
/// </summary>
|
|
public class SyslogServer
|
|
{
|
|
/// <summary>
|
|
/// Hostname.
|
|
/// </summary>
|
|
public string Hostname
|
|
{
|
|
get
|
|
{
|
|
return _Hostname;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(Hostname));
|
|
_Hostname = value;
|
|
|
|
SetUdp();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UDP port.
|
|
/// </summary>
|
|
public int Port
|
|
{
|
|
get
|
|
{
|
|
return _Port;
|
|
}
|
|
set
|
|
{
|
|
if (value < 0) throw new ArgumentException("Port must be zero or greater.");
|
|
_Port = value;
|
|
|
|
SetUdp();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// IP:port of the server.
|
|
/// </summary>
|
|
public string IpPort
|
|
{
|
|
get
|
|
{
|
|
return _Hostname + ":" + _Port;
|
|
}
|
|
}
|
|
|
|
internal readonly object SendLock = new object();
|
|
internal UdpClient Udp = null;
|
|
private string _Hostname = "127.0.0.1";
|
|
private int _Port = 514;
|
|
|
|
/// <summary>
|
|
/// Instantiate the object.
|
|
/// </summary>
|
|
public SyslogServer()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Instantiate the object.
|
|
/// </summary>
|
|
/// <param name="hostname">Hostname.</param>
|
|
/// <param name="port">Port.</param>
|
|
public SyslogServer(string hostname = "127.0.0.1", int port = 514)
|
|
{
|
|
Hostname = hostname;
|
|
Port = port;
|
|
}
|
|
|
|
private void SetUdp()
|
|
{
|
|
Udp = null;
|
|
Udp = new UdpClient(_Hostname, _Port);
|
|
}
|
|
}
|
|
}
|