Skip to content

Allow to configure restrictedToMinimumLevel via LoggingLevelSwitch #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static class SeqLoggerConfigurationExtensions
/// <param name="serverUrl">The base URL of the Seq server that log events will be written to.</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required
/// in order to write an event to the sink.</param>
/// <param name="restrictedToMinimumLevelSwitch">The switch controlling the minimum log event level required
/// in order to write an event to the sink.
/// Notice, if the parameter is specified, the <paramref name="restrictedToMinimumLevel"/> should not be used.</param>
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
/// <param name="period">The time to wait between checking for event batches.</param>
/// <param name="bufferBaseFilename">Path for a set of files that will be used to buffer events until they
Expand Down Expand Up @@ -73,6 +76,7 @@ public static LoggerConfiguration Seq(
this LoggerSinkConfiguration loggerSinkConfiguration,
string serverUrl,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
LoggingLevelSwitch? restrictedToMinimumLevelSwitch = null,
int batchPostingLimit = DefaultBatchPostingLimit,
TimeSpan? period = null,
string? apiKey = null,
Expand Down Expand Up @@ -115,7 +119,7 @@ public static LoggerConfiguration Seq(

return loggerSinkConfiguration.Conditional(
controlledSwitch.IsIncluded,
wt => wt.Sink(batchedSink, options, restrictedToMinimumLevel, levelSwitch: null));
wt => wt.Sink(batchedSink, options, restrictedToMinimumLevel, restrictedToMinimumLevelSwitch));
}

var sink = new DurableSeqSink(
Expand All @@ -131,7 +135,7 @@ public static LoggerConfiguration Seq(

return loggerSinkConfiguration.Conditional(
controlledSwitch.IsIncluded,
wt => wt.Sink(sink, restrictedToMinimumLevel, levelSwitch: null));
wt => wt.Sink(sink, restrictedToMinimumLevel, restrictedToMinimumLevelSwitch));
}

/// <summary>
Expand All @@ -142,6 +146,9 @@ public static LoggerConfiguration Seq(
/// <param name="serverUrl">The base URL of the Seq server that log events will be written to.</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required
/// in order to write an event to the sink.</param>
/// <param name="restrictedToMinimumLevelSwitch">The switch controlling the minimum log event level required
/// in order to write an event to the sink.
/// Notice, if the parameter is specified, the <paramref name="restrictedToMinimumLevel"/> should not be used.</param>
/// <param name="apiKey">A Seq <i>API key</i> that authenticates the client to the Seq server.</param>
/// <param name="messageHandler">Used to construct the HttpClient that will send the log messages to Seq.</param>
/// <param name="payloadFormatter">An <see cref="ITextFormatter"/> that will be used to format (newline-delimited CLEF/JSON)
Expand All @@ -153,6 +160,7 @@ public static LoggerConfiguration Seq(
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
string serverUrl,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
LoggingLevelSwitch? restrictedToMinimumLevelSwitch = null,
string? apiKey = null,
HttpMessageHandler? messageHandler = null,
ITextFormatter? payloadFormatter = null,
Expand All @@ -163,6 +171,6 @@ public static LoggerConfiguration Seq(

var ingestionApi = new SeqIngestionApiClient(serverUrl, apiKey, messageHandler);
var sink = new SeqAuditSink(ingestionApi, payloadFormatter ?? CreateDefaultFormatter(formatProvider));
return loggerAuditSinkConfiguration.Sink(sink, restrictedToMinimumLevel);
return loggerAuditSinkConfiguration.Sink(sink, restrictedToMinimumLevel, restrictedToMinimumLevelSwitch);
}
}