Skip to content

Commit 67e1e41

Browse files
committed
Created class documentation
#8
1 parent eec8e43 commit 67e1e41

16 files changed

+361
-8
lines changed

src/SplunkLogger/BatchManager.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@
66

77
namespace Splunk
88
{
9+
/// <summary>
10+
/// Class used at HEC loggers to control batch process.
11+
/// </summary>
912
public class BatchManager
1013
{
11-
ConcurrentBag<object> events;
14+
readonly ConcurrentBag<object> events;
15+
readonly uint batchSizeCount;
16+
readonly uint batchIntervalInMiliseconds;
17+
readonly Timer timer;
18+
readonly Action<List<object>> emitAction;
19+
1220
bool isDisposed;
1321
bool isDisposing;
14-
uint batchSizeCount;
15-
uint batchIntervalInMiliseconds;
16-
Timer timer;
17-
Action<List<object>> emitAction;
1822

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="T:Splunk.BatchManager"/> class.
25+
/// </summary>
26+
/// <param name="batchSizeCount">Batch size count.</param>
27+
/// <param name="batchIntervalInMiliseconds">Batch interval in miliseconds.</param>
28+
/// <param name="emitAction">Emit action to be invoked at Emit process.</param>
1929
public BatchManager(uint batchSizeCount, uint batchIntervalInMiliseconds, Action<List<object>> emitAction)
2030
{
2131
events = new ConcurrentBag<object>();
@@ -69,6 +79,10 @@ void Emit()
6979
emitAction?.Invoke(emitEvents);
7080
}
7181

82+
/// <summary>
83+
/// Add the specified item for futher batch emit process.
84+
/// </summary>
85+
/// <param name="item">Item to be added for next batch emit process.</param>
7286
public void Add(object item)
7387
{
7488
if (!isDisposed && !isDisposing)
@@ -79,6 +93,14 @@ public void Add(object item)
7993
}
8094
}
8195

96+
/// <summary>
97+
/// Releases all resource used by the <see cref="T:Splunk.BatchManager"/> object.
98+
/// </summary>
99+
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="T:Splunk.BatchManager"/>. The
100+
/// <see cref="Dispose"/> method leaves the <see cref="T:Splunk.BatchManager"/> in an unusable state. After
101+
/// calling <see cref="Dispose"/>, you must release all references to the <see cref="T:Splunk.BatchManager"/> so
102+
/// the garbage collector can reclaim the memory that the <see cref="T:Splunk.BatchManager"/> was occupying.
103+
/// </remarks>
82104
public void Dispose()
83105
{
84106
if (!isDisposed)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11

22
namespace Splunk.Configurations
33
{
4+
/// <summary>
5+
/// Class used to define configuration for Splunk HEC logger.
6+
/// </summary>
47
public class HECConfiguration
58
{
9+
/// <summary>
10+
/// Gets or sets the batch interval in miliseconds.
11+
/// </summary>
612
public uint BatchIntervalInMiliseconds { get; set; } = 5000; // 5 seconds
13+
14+
/// <summary>
15+
/// Gets or sets the batch size count.
16+
/// </summary>
717
public uint BatchSizeCount { get; set; } = 10;
18+
19+
/// <summary>
20+
/// Gets or sets the default timeout in miliseconds.
21+
/// </summary>
822
public int DefaultTimeoutInMiliseconds { get; set; } = 10000; // 10 seconds
23+
24+
/// <summary>
25+
/// Gets or sets the splunk collector URL.
26+
/// </summary>
927
public string SplunkCollectorUrl { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the token.
31+
/// </summary>
1032
public string Token { get; set; }
1133
}
1234
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11

22
namespace Splunk.Configurations
33
{
4+
/// <summary>
5+
/// Class used to define configuration for Splunk Socket logger.
6+
/// </summary>
47
public class SocketConfiguration
58
{
9+
/// <summary>
10+
/// Gets or sets the name of the host.
11+
/// </summary>
612
public string HostName { get; set; }
13+
14+
/// <summary>
15+
/// Gets or sets the port.
16+
/// </summary>
717
public int Port { get; set; }
818
}
919
}

src/SplunkLogger/Configurations/SplunkLoggerConfiguration.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22

33
namespace Splunk.Configurations
44
{
5+
/// <summary>
6+
/// Class used to define configuration for Splunk logger.
7+
/// </summary>
58
public class SplunkLoggerConfiguration
69
{
10+
/// <summary>
11+
/// Gets or sets the hec configuration.
12+
/// </summary>
13+
/// <value>The hec configuration.</value>
714
public HECConfiguration HecConfiguration { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the socket configuration.
18+
/// </summary>
19+
/// <value>The socket configuration.</value>
820
public SocketConfiguration SocketConfiguration { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the threshold.
24+
/// </summary>
25+
/// <value>The threshold.</value>
926
public LogLevel Threshold { get; set; } = LogLevel.Warning;
1027
}
1128
}

src/SplunkLogger/ILoggerFormatter.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,31 @@
33

44
namespace Splunk
55
{
6+
/// <summary>
7+
/// Define a formatter capable to provide a custom text or json entry for log.
8+
/// </summary>
69
public interface ILoggerFormatter
710
{
11+
/// <summary>
12+
/// Format the specified logLevel, eventId, state and exception into log string entry.
13+
/// </summary>
14+
/// <returns>Formatted log string.</returns>
15+
/// <param name="logLevel">Log level.</param>
16+
/// <param name="eventId">Event identifier.</param>
17+
/// <param name="state">Log object state.</param>
18+
/// <param name="exception">Log exception.</param>
19+
/// <typeparam name="T">Log entry.</typeparam>
820
string Format<T>(LogLevel logLevel, EventId eventId, T state, Exception exception);
21+
22+
/// <summary>
23+
/// Formats the specified logLevel, eventId, state and exception into json entry.
24+
/// </summary>
25+
/// <returns>The json.</returns>
26+
/// <param name="logLevel">Log level.</param>
27+
/// <param name="eventId">Event identifier.</param>
28+
/// <param name="state">Log object state.</param>
29+
/// <param name="exception">Log exception.</param>
30+
/// <typeparam name="T">Log entry.</typeparam>
931
SplunkJSONEntry FormatJson<T>(LogLevel logLevel, EventId eventId, T state, Exception exception);
1032
}
1133
}

src/SplunkLogger/Loggers/BaseLogger.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,42 @@
33

44
namespace Splunk.Loggers
55
{
6+
/// <summary>
7+
/// Define a base logger class.
8+
/// </summary>
69
public abstract class BaseLogger
710
{
811
protected readonly ILoggerFormatter loggerFormatter;
912

1013
readonly string categoryName;
1114
readonly LogLevel threshold;
1215

16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="T:Splunk.Loggers.BaseLogger"/> class.
18+
/// </summary>
19+
/// <param name="categoryName">Category name.</param>
20+
/// <param name="threshold">Threshold.</param>
21+
/// <param name="loggerFormatter">Formatter instance.</param>
1322
public BaseLogger(string categoryName, LogLevel threshold, ILoggerFormatter loggerFormatter)
1423
{
1524
this.categoryName = categoryName;
1625
this.threshold = threshold;
1726
this.loggerFormatter = loggerFormatter;
1827
}
1928

29+
/// <summary>
30+
/// Ises the enabled.
31+
/// </summary>
32+
/// <returns><c>true</c>, if log level is equal ou higher than threshold, <c>false</c> otherwise.</returns>
33+
/// <param name="logLevel">.Net Core Log level.</param>
2034
public bool IsEnabled(LogLevel logLevel)
2135
{
2236
return (int)logLevel >= (int)threshold;
2337
}
2438

39+
/// <summary>
40+
/// Not implemented method. DO NOT USE IT.
41+
/// </summary>
2542
public IDisposable BeginScope<T>(T state)
2643
{
2744
return null;

src/SplunkLogger/Loggers/HECBaseLogger.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
using System;
2-
using System.Net.Http;
1+
using System.Net.Http;
32
using Microsoft.Extensions.Logging;
43

54
namespace Splunk.Loggers
65
{
6+
/// <summary>
7+
/// Define a base HEC logger class.
8+
/// </summary>
79
public abstract class HECBaseLogger : BaseLogger
810
{
911
protected readonly BatchManager batchManager;
1012

1113
readonly HttpClient httpClient;
1214

15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="T:Splunk.Loggers.HECBaseLogger"/> class.
17+
/// </summary>
18+
/// <param name="categoryName">Category name.</param>
19+
/// <param name="threshold">Threshold.</param>
20+
/// <param name="httpClient">Http client.</param>
21+
/// <param name="batchManager">Batch manager.</param>
22+
/// <param name="loggerFormatter">Formatter instance.</param>
1323
public HECBaseLogger(string categoryName, LogLevel threshold, HttpClient httpClient, BatchManager batchManager, ILoggerFormatter loggerFormatter)
1424
: base(categoryName, threshold, loggerFormatter)
1525
{

src/SplunkLogger/Loggers/HECJsonLogger.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@
55

66
namespace Splunk.Loggers
77
{
8+
/// <summary>
9+
/// Class used to send log to splunk as JSON via HEC.
10+
/// </summary>
811
public class HECJsonLogger : HECBaseLogger, ILogger
912
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="T:Splunk.Loggers.HECJsonLogger"/> class.
15+
/// </summary>
16+
/// <param name="categoryName">Category name.</param>
17+
/// <param name="threshold">Threshold.</param>
18+
/// <param name="httpClient">Http client.</param>
19+
/// <param name="batchManager">Batch manager.</param>
20+
/// <param name="loggerFormatter">Formatter instance.</param>
1021
public HECJsonLogger(string categoryName, LogLevel threshold, HttpClient httpClient, BatchManager batchManager, ILoggerFormatter loggerFormatter)
1122
: base(categoryName, threshold, httpClient, batchManager, loggerFormatter)
1223
{
1324
}
1425

26+
/// <summary>
27+
/// Method used to create log.
28+
/// </summary>
29+
/// <returns>The log.</returns>
30+
/// <param name="logLevel">Log level.</param>
31+
/// <param name="eventId">Log event identifier.</param>
32+
/// <param name="state">Log object state.</param>
33+
/// <param name="exception">Log Exception.</param>
34+
/// <param name="formatter">Log text formatter function.</param>
1535
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
1636
{
1737
SplunkJSONEntry formatedMessage = null;

src/SplunkLogger/Loggers/HECRawLogger.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,33 @@
44

55
namespace Splunk.Loggers
66
{
7+
/// <summary>
8+
/// Class used to send log to splunk as RAW via HEC.
9+
/// </summary>
710
public class HECRawLogger : HECBaseLogger, ILogger
811
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="T:Splunk.Loggers.HECRawLogger"/> class.
14+
/// </summary>
15+
/// <param name="categoryName">Category name.</param>
16+
/// <param name="threshold">Threshold.</param>
17+
/// <param name="httpClient">Http client.</param>
18+
/// <param name="batchManager">Batch manager.</param>
19+
/// <param name="loggerFormatter">Formatter instance.</param>
920
public HECRawLogger(string categoryName, LogLevel threshold, HttpClient httpClient, BatchManager batchManager, ILoggerFormatter loggerFormatter)
1021
: base(categoryName, threshold, httpClient, batchManager, loggerFormatter)
1122
{
1223
}
1324

25+
/// <summary>
26+
/// Method used to create log.
27+
/// </summary>
28+
/// <returns>The log.</returns>
29+
/// <param name="logLevel">Log level.</param>
30+
/// <param name="eventId">Log event identifier.</param>
31+
/// <param name="state">Log object state.</param>
32+
/// <param name="exception">Log Exception.</param>
33+
/// <param name="formatter">Log text formatter function.</param>
1434
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
1535
{
1636
string formatedMessage = string.Empty;

src/SplunkLogger/Loggers/TcpLogger.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@
55

66
namespace Splunk.Loggers
77
{
8+
/// <summary>
9+
/// Class used to send log to splunk via tcp.
10+
/// </summary>
811
public class TcpLogger : BaseLogger, ILogger
912
{
1013
readonly TcpClient tcpClient;
1114

15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="T:Splunk.Loggers.TcpLogger"/> class.
17+
/// </summary>
18+
/// <param name="categoryName">Category name.</param>
19+
/// <param name="threshold">Threshold.</param>
20+
/// <param name="tcpClient">Tcp client.</param>
21+
/// <param name="loggerFormatter">Formatter instance.</param>
1222
public TcpLogger(string categoryName, LogLevel threshold, TcpClient tcpClient, ILoggerFormatter loggerFormatter)
1323
: base(categoryName, threshold, loggerFormatter)
1424
{
1525
this.tcpClient = tcpClient;
1626
}
1727

28+
/// <summary>
29+
/// Method used to create log.
30+
/// </summary>
31+
/// <returns>The log.</returns>
32+
/// <param name="logLevel">Log level.</param>
33+
/// <param name="eventId">Log event identifier.</param>
34+
/// <param name="state">Log object state.</param>
35+
/// <param name="exception">Log Exception.</param>
36+
/// <param name="formatter">Log text formatter function.</param>
1837
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
1938
{
2039
string formatedMessage = string.Empty;

0 commit comments

Comments
 (0)