Updated
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Net;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
using EonaCat.Json;
|
using EonaCat.Json;
|
||||||
using EonaCat.Logger.Extensions;
|
using EonaCat.Logger.Extensions;
|
||||||
using EonaCat.Logger.GrayLog;
|
using EonaCat.Logger.GrayLog;
|
||||||
@@ -135,9 +136,9 @@ namespace EonaCat.Logger.Managers
|
|||||||
logger.Log(logLevel, message);
|
logger.Log(logLevel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task SendToSplunkServersAsync(LoggerSettings settings, string logType, string message, bool sendToSplunkServer)
|
public static async Task SendToSplunkServersAsync(LoggerSettings settings, string jsonPayload, bool sendToSplunkServer)
|
||||||
{
|
{
|
||||||
if (settings == null || !sendToSplunkServer || string.IsNullOrWhiteSpace(message))
|
if (settings == null || !sendToSplunkServer || string.IsNullOrWhiteSpace(jsonPayload))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (settings.SplunkServers == null)
|
if (settings.SplunkServers == null)
|
||||||
@@ -166,15 +167,7 @@ namespace EonaCat.Logger.Managers
|
|||||||
{
|
{
|
||||||
using (var httpClient = new HttpClient(splunkServer.SplunkClientHandler))
|
using (var httpClient = new HttpClient(splunkServer.SplunkClientHandler))
|
||||||
{
|
{
|
||||||
var payload = new
|
|
||||||
{
|
|
||||||
log_message = message,
|
|
||||||
sourcetype = logType
|
|
||||||
};
|
|
||||||
|
|
||||||
var jsonPayload = JsonHelper.ToJson(payload);
|
|
||||||
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
httpClient.DefaultRequestHeaders.Add("Authorization", $"Splunk {splunkServer.SplunkHecToken}");
|
httpClient.DefaultRequestHeaders.Add("Authorization", $"Splunk {splunkServer.SplunkHecToken}");
|
||||||
|
|
||||||
var response = await httpClient.PostAsync(splunkServer.SplunkHecUrl, content);
|
var response = await httpClient.PostAsync(splunkServer.SplunkHecUrl, content);
|
||||||
@@ -193,6 +186,19 @@ namespace EonaCat.Logger.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task SendToSplunkServersAsync(LoggerSettings settings, string logType, string message, bool sendToSplunkServer)
|
||||||
|
{
|
||||||
|
if (settings == null || !sendToSplunkServer || string.IsNullOrWhiteSpace(message))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var jsonPayload = JsonHelper.ToJson(new
|
||||||
|
{
|
||||||
|
@event = message,
|
||||||
|
sourcetype = logType
|
||||||
|
});
|
||||||
|
await SendToSplunkServersAsync(settings, logType, jsonPayload, sendToSplunkServer);
|
||||||
|
}
|
||||||
|
|
||||||
internal static async Task SendToGrayLogServersAsync(LoggerSettings settings, string message, ELogType logLevel, string facility, string source, bool sendToGrayLogServer, string version = "1.1")
|
internal static async Task SendToGrayLogServersAsync(LoggerSettings settings, string message, ELogType logLevel, string facility, string source, bool sendToGrayLogServer, string version = "1.1")
|
||||||
{
|
{
|
||||||
if (settings == null || !sendToGrayLogServer || string.IsNullOrWhiteSpace(message))
|
if (settings == null || !sendToGrayLogServer || string.IsNullOrWhiteSpace(message))
|
||||||
|
|||||||
Reference in New Issue
Block a user