diff --git a/EonaCat.Logger/EonaCat.Logger.csproj b/EonaCat.Logger/EonaCat.Logger.csproj
index 8d907f0..ed3d15e 100644
--- a/EonaCat.Logger/EonaCat.Logger.csproj
+++ b/EonaCat.Logger/EonaCat.Logger.csproj
@@ -3,7 +3,7 @@
.netstandard2.1; net6.0; net7.0; net8.0; net4.8;
icon.ico
latest
- 1.4.4
+ 1.4.5
EonaCat (Jeroen Saey)
true
EonaCat (Jeroen Saey)
@@ -24,7 +24,7 @@
- 1.4.4+{chash:10}.{c:ymd}
+ 1.4.5+{chash:10}.{c:ymd}
true
true
v[0-9]*
diff --git a/EonaCat.Logger/Managers/LogHelper.cs b/EonaCat.Logger/Managers/LogHelper.cs
index e88d3e0..f775502 100644
--- a/EonaCat.Logger/Managers/LogHelper.cs
+++ b/EonaCat.Logger/Managers/LogHelper.cs
@@ -259,7 +259,7 @@ public static class LogHelper
return;
}
- var isEnabled = (splunkServer?.TypesToLog == null || splunkServer.TypesToLog.Count == 0 || splunkServer.TypesToLog.Contains(currentLogType));
+ var isEnabled = (splunkServer?.TypesToLog == null || splunkServer?.TypesToLog.Count == 0 || splunkServer.TypesToLog.Contains(currentLogType));
if (!isEnabled)
{
splunkServer?.DisposeHttpClient();
@@ -267,15 +267,15 @@ public static class LogHelper
}
}
- var response = await splunkServer.SendAsync(splunkPayload, disableSplunkSSL);
+ var response = await splunkServer?.SendAsync(splunkPayload, disableSplunkSSL);
if (!response.IsSuccessStatusCode)
{
- LogError($"Failed to send log to Splunk '{splunkServer.SplunkHecUrl}'. Status code: {response.StatusCode}");
+ LogError($"Failed to send log to Splunk '{splunkServer?.SplunkHecUrl}'. Status code: {response.StatusCode}");
}
}
catch (Exception ex)
{
- LogError($"Error logging to Splunk '{splunkServer.SplunkHecUrl}': {ex.Message}", ex);
+ LogError($"Error logging to Splunk '{splunkServer?.SplunkHecUrl}': {ex.Message}", ex);
}
}) ?? new List();
@@ -365,13 +365,13 @@ public static class LogHelper
if (!grayLogServer.IsConnected)
{
- grayLogServer.SetUdp();
+ grayLogServer?.SetUdp();
}
if (messageBytes.Length <= MaxUdpPacketSize)
{
// Send via UDP (single packet)
- await grayLogServer.Udp.SendAsync(messageBytes, messageBytes.Length);
+ await grayLogServer?.Udp.SendAsync(messageBytes, messageBytes.Length);
}
else if (grayLogServer.SupportsTcp)
{
@@ -402,6 +402,10 @@ public static class LogHelper
///
private static async Task SendViaTcpAsync(Graylog server, byte[] data)
{
+ if (server == null)
+ {
+ return;
+ }
using var tcpClient = new System.Net.Sockets.TcpClient();
await tcpClient.ConnectAsync(server.Hostname, server.Port);
using var stream = tcpClient.GetStream();
@@ -414,6 +418,10 @@ public static class LogHelper
///
private static async Task SendUdpInChunksAsync(Graylog server, byte[] data, int chunkSize)
{
+ if (server == null)
+ {
+ return;
+ }
for (int i = 0; i < data.Length; i += chunkSize)
{
var chunk = data.Skip(i).Take(chunkSize).ToArray();
diff --git a/EonaCat.Logger/Servers/Syslog/Syslog.cs b/EonaCat.Logger/Servers/Syslog/Syslog.cs
index fb5af25..e7f24fb 100644
--- a/EonaCat.Logger/Servers/Syslog/Syslog.cs
+++ b/EonaCat.Logger/Servers/Syslog/Syslog.cs
@@ -98,7 +98,7 @@ public class Syslog : IDisposable
try
{
Udp?.Close();
- Udp.Dispose();
+ Udp?.Dispose();
}
catch
{
@@ -127,10 +127,20 @@ public class Syslog : IDisposable
private async Task SendAsync(byte[] data)
{
+ if (data == null)
+ {
+ return;
+ }
+
+ if (Udp == null)
+ {
+ return;
+ }
+
if (data.Length <= MaxUdpPacketSize)
{
// Send via UDP (single packet)
- await Udp.SendAsync(data, data.Length);
+ await Udp?.SendAsync(data, data.Length);
}
else if (SupportsTcp)
{
@@ -149,6 +159,11 @@ public class Syslog : IDisposable
///
private static async Task SendViaTcpAsync(Servers.Syslog.Syslog server, byte[] data)
{
+ if (server == null)
+ {
+ return;
+ }
+
using var tcpClient = new System.Net.Sockets.TcpClient();
await tcpClient.ConnectAsync(server.Hostname, server.Port);
using var stream = tcpClient.GetStream();
diff --git a/EonaCat.Logger/Servers/Udp/Udp.cs b/EonaCat.Logger/Servers/Udp/Udp.cs
index 66ce754..b0471f4 100644
--- a/EonaCat.Logger/Servers/Udp/Udp.cs
+++ b/EonaCat.Logger/Servers/Udp/Udp.cs
@@ -128,7 +128,7 @@ namespace EonaCat.Logger.Servers.Udp
byte[] chunk = new byte[chunkSize];
Array.Copy(data, offset, chunk, 0, chunkSize);
- await _udp.SendAsync(chunk, chunk.Length);
+ await _udp?.SendAsync(chunk, chunk.Length);
offset += chunkSize;
}
}
@@ -160,7 +160,7 @@ namespace EonaCat.Logger.Servers.Udp
byte[] chunk = new byte[chunkSize];
Array.Copy(sendData, offset, chunk, 0, chunkSize);
- await _udp.SendAsync(chunk, chunk.Length);
+ await _udp?.SendAsync(chunk, chunk.Length);
offset += chunkSize;
}
}
diff --git a/EonaCat.Logger/Servers/Zabbix/ZabbixRequest.cs b/EonaCat.Logger/Servers/Zabbix/ZabbixRequest.cs
index 1ee70a2..bbac506 100644
--- a/EonaCat.Logger/Servers/Zabbix/ZabbixRequest.cs
+++ b/EonaCat.Logger/Servers/Zabbix/ZabbixRequest.cs
@@ -44,6 +44,11 @@ namespace EonaCat.Logger.Servers.Zabbix
///
public async Task SendAsync(string server, int port = 10051, int timeout = 500)
{
+ if (string.IsNullOrWhiteSpace(server))
+ {
+ return new ZabbixResponse();
+ }
+
string json = JsonHelper.ToJson(new ZabbixRequest(Data[0].Host, Data[0].Key, Data[0].Value));
using (TcpClient tcpClient = new TcpClient(server, port))
using (NetworkStream stream = tcpClient.GetStream())