Updated
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<TargetFrameworks>.netstandard2.1; net6.0; net7.0; net8.0; net4.8;</TargetFrameworks>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<FileVersion>1.4.4</FileVersion>
|
||||
<FileVersion>1.4.5</FileVersion>
|
||||
<Authors>EonaCat (Jeroen Saey)</Authors>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Company>EonaCat (Jeroen Saey)</Company>
|
||||
@@ -24,7 +24,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<EVRevisionFormat>1.4.4+{chash:10}.{c:ymd}</EVRevisionFormat>
|
||||
<EVRevisionFormat>1.4.5+{chash:10}.{c:ymd}</EVRevisionFormat>
|
||||
<EVDefault>true</EVDefault>
|
||||
<EVInfo>true</EVInfo>
|
||||
<EVTagMatch>v[0-9]*</EVTagMatch>
|
||||
|
||||
@@ -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<Task>();
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ namespace EonaCat.Logger.Servers.Zabbix
|
||||
/// <exception cref="TimeoutException"></exception>
|
||||
public async Task<ZabbixResponse> 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())
|
||||
|
||||
Reference in New Issue
Block a user