Skip to content

Commit d9210ba

Browse files
author
NivalXer
authored
Fix Serilog.MinimumLevel not working and use restrictedToMinimumLevel (#17)
* fix Serilog.MinimumLevel not working and use restrictedToMinimumLevel to set default level * optimize eventbuilder allocations. merge GetLevel method
1 parent da657af commit d9210ba

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/Serilog.Sinks.Exceptionless/LoggerSinkConfigurationExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static LoggerConfiguration Exceptionless(
3232
if (apiKey == null)
3333
throw new ArgumentNullException(nameof(apiKey));
3434

35-
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, null, null, additionalOperation, includeProperties), restrictedToMinimumLevel);
35+
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, null, null, additionalOperation, includeProperties, restrictedToMinimumLevel), restrictedToMinimumLevel);
3636
}
3737

3838
/// <summary>Creates a new Exceptionless sink with the specified <paramref name="apiKey"/>.</summary>
@@ -60,7 +60,7 @@ public static LoggerConfiguration Exceptionless(
6060
if (apiKey == null)
6161
throw new ArgumentNullException(nameof(apiKey));
6262

63-
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, serverUrl, defaultTags, additionalOperation, includeProperties), restrictedToMinimumLevel);
63+
return loggerConfiguration.Sink(new ExceptionlessSink(apiKey, serverUrl, defaultTags, additionalOperation, includeProperties, restrictedToMinimumLevel), restrictedToMinimumLevel);
6464
}
6565

6666
/// <summary>Creates a new Exceptionless sink.</summary>

src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessClientExtensions.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, L
1313

1414
var builder = log.Exception != null
1515
? client.CreateException(log.Exception)
16-
: client.CreateLog(log.GetSource(), message, log.GetLevel());
16+
: client.CreateLog(log.GetSource(), message, log.Level.GetLevel());
1717

1818
builder.Target.Date = log.Timestamp;
1919
if (log.Level == LogEventLevel.Fatal)
@@ -36,8 +36,10 @@ internal static string GetSource(this LogEvent log) {
3636
return null;
3737
}
3838

39-
internal static LogLevel GetLevel(this LogEvent log) {
40-
switch (log.Level) {
39+
internal static LogLevel GetLevel(this LogEventLevel log)
40+
{
41+
switch (log)
42+
{
4143
case LogEventLevel.Verbose:
4244
return LogLevel.Trace;
4345
case LogEventLevel.Debug:

src/Serilog.Sinks.Exceptionless/Sinks/Exceptionless/ExceptionlessSink.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ public class ExceptionlessSink : ILogEventSink, IDisposable {
3737
/// <param name="includeProperties">
3838
/// If false then the Serilog properties will not be submitted to Exceptionless
3939
/// </param>
40+
/// <param name="restrictedToMinimumLevel">
41+
/// The minimum log event level required in order to write an event to the sink.
42+
/// </param>
4043
public ExceptionlessSink(
4144
string apiKey,
4245
string serverUrl = null,
4346
string[] defaultTags = null,
4447
Func<EventBuilder, EventBuilder> additionalOperation = null,
45-
bool includeProperties = true
48+
bool includeProperties = true,
49+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
4650
) {
4751
if (apiKey == null)
4852
throw new ArgumentNullException(nameof(apiKey));
@@ -56,6 +60,7 @@ public ExceptionlessSink(
5660

5761
config.UseInMemoryStorage();
5862
config.UseLogger(new SelfLogLogger());
63+
config.SetDefaultMinLogLevel(restrictedToMinimumLevel.GetLevel());
5964
});
6065

6166
_defaultTags = defaultTags;
@@ -93,6 +98,10 @@ public void Emit(LogEvent logEvent) {
9398
if (logEvent == null || !_client.Configuration.IsValid)
9499
return;
95100

101+
var minLogLevel = _client.Configuration.Settings.GetMinLogLevel(logEvent.GetSource());
102+
if (logEvent.Level.GetLevel() < minLogLevel)
103+
return;
104+
96105
var builder = _client.CreateFromLogEvent(logEvent).AddTags(_defaultTags);
97106

98107
if (_includeProperties && logEvent.Properties != null) {

0 commit comments

Comments
 (0)