Skip to content

Commit dc017ce

Browse files
committed
Implemented JSON HEC logger class
#5
1 parent 1a40a23 commit dc017ce

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Net.Http;
3+
using Microsoft.Extensions.Logging;
4+
using Newtonsoft.Json.Linq;
5+
6+
namespace Splunk.Loggers
7+
{
8+
public class HECJsonLogger : HECBaseLogger, ILogger
9+
{
10+
public HECJsonLogger(string categoryName, LogLevel threshold, HttpClient httpClient, BatchManager batchManager, ILoggerFormatter loggerFormatter)
11+
: base(categoryName, threshold, httpClient, batchManager, loggerFormatter)
12+
{
13+
}
14+
15+
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
16+
{
17+
SplunkJSONEntry formatedMessage = null;
18+
if (loggerFormatter != null)
19+
formatedMessage = loggerFormatter.FormatJson(logLevel, eventId, state, exception);
20+
else if (formatter != null)
21+
formatedMessage = new SplunkJSONEntry(formatter(state, exception));
22+
batchManager.Add(JObject.FromObject(formatedMessage));
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)