Skip to content

Commit 236f82e

Browse files
authored
Merge pull request #79 from vanthoainguyen/dev
Add optional LoggingLevelSwitch param to EventCollector extension methods
2 parents 2bc05b2 + 912c362 commit 236f82e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using System.Net.Http;
1818
using Serilog.Configuration;
19+
using Serilog.Core;
1920
using Serilog.Events;
2021
using Serilog.Formatting;
2122
using Serilog.Sinks.Splunk;
@@ -53,6 +54,7 @@ public static class SplunkLoggingConfigurationExtensions
5354
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
5455
/// <param name="batchSizeLimit">The size of the batch</param>
5556
/// <param name="messageHandler">The handler used to send HTTP requests</param>
57+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
5658
/// <returns></returns>
5759
public static LoggerConfiguration EventCollector(
5860
this LoggerSinkConfiguration configuration,
@@ -69,7 +71,8 @@ public static LoggerConfiguration EventCollector(
6971
bool renderTemplate = true,
7072
int batchIntervalInSeconds = 2,
7173
int batchSizeLimit = 100,
72-
HttpMessageHandler messageHandler = null)
74+
HttpMessageHandler messageHandler = null,
75+
LoggingLevelSwitch levelSwitch = null)
7376
{
7477
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
7578
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
@@ -88,7 +91,7 @@ public static LoggerConfiguration EventCollector(
8891
renderTemplate,
8992
messageHandler);
9093

91-
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
94+
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch);
9295
}
9396

9497
/// <summary>
@@ -104,6 +107,7 @@ public static LoggerConfiguration EventCollector(
104107
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
105108
/// <param name="batchSizeLimit">The size of the batch</param>
106109
/// <param name="messageHandler">The handler used to send HTTP requests</param>
110+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
107111
/// <returns></returns>
108112
public static LoggerConfiguration EventCollector(
109113
this LoggerSinkConfiguration configuration,
@@ -115,7 +119,8 @@ public static LoggerConfiguration EventCollector(
115119
string outputTemplate = DefaultOutputTemplate,
116120
int batchIntervalInSeconds = 2,
117121
int batchSizeLimit = 100,
118-
HttpMessageHandler messageHandler = null)
122+
HttpMessageHandler messageHandler = null,
123+
LoggingLevelSwitch levelSwitch = null)
119124
{
120125
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
121126
if (jsonFormatter == null) throw new ArgumentNullException(nameof(jsonFormatter));
@@ -130,10 +135,10 @@ public static LoggerConfiguration EventCollector(
130135
jsonFormatter,
131136
messageHandler);
132137

133-
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
138+
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch);
134139
}
135140

136-
141+
137142
/// <summary>
138143
/// Adds a sink that writes log events as to a Splunk instance via the HTTP Event Collector.
139144
/// </summary>
@@ -152,6 +157,7 @@ public static LoggerConfiguration EventCollector(
152157
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
153158
/// <param name="batchSizeLimit">The size of the batch</param>
154159
/// <param name="messageHandler">The handler used to send HTTP requests</param>
160+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
155161
/// <param name="fields">Customfields that will be indexed in splunk with this event</param>
156162
/// <returns></returns>
157163
public static LoggerConfiguration EventCollector(
@@ -170,7 +176,8 @@ public static LoggerConfiguration EventCollector(
170176
bool renderTemplate = true,
171177
int batchIntervalInSeconds = 2,
172178
int batchSizeLimit = 100,
173-
HttpMessageHandler messageHandler = null)
179+
HttpMessageHandler messageHandler = null,
180+
LoggingLevelSwitch levelSwitch = null)
174181
{
175182
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
176183
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
@@ -191,7 +198,7 @@ public static LoggerConfiguration EventCollector(
191198
messageHandler
192199
);
193200

194-
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
201+
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel, levelSwitch);
195202
}
196203
}
197204
}

0 commit comments

Comments
 (0)