Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Added logLevelSwitch option #139

Merged
merged 2 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public static LoggerConfiguration Elasticsearch(
? (ILogEventSink)new ElasticsearchSink(options)
: new DurableElasticsearchSink(options);

return loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel ?? LevelAlias.Minimum);
return loggerSinkConfiguration.Sink(
sink,
restrictedToMinimumLevel : options.MinimumLogEventLevel ?? LevelAlias.Minimum,
levelSwitch : options.LoggingLevelSwitch
);
}

/// <summary>
Expand All @@ -69,7 +73,8 @@ public static LoggerConfiguration Elasticsearch(
/// <param name="batchPostingLimit"><see cref="ElasticsearchSinkOptions.BatchPostingLimit"/></param>
/// <param name="period"><see cref="ElasticsearchSinkOptions.Period"/></param>
/// <param name="inlineFields"><see cref="ElasticsearchSinkOptions.InlineFields"/></param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink. Ignored when <paramref name="loggingLevelSwitch"/> is specified.</param>
/// <param name="loggingLevelSwitch" > A switch allowing the pass-through minimum level to be changed at runtime.</param>
/// <param name="bufferBaseFilename"><see cref="ElasticsearchSinkOptions.BufferBaseFilename"/></param>
/// <param name="bufferFileSizeLimitBytes"><see cref="ElasticsearchSinkOptions.BufferFileSizeLimitBytes"/></param>
/// <param name="bufferLogShippingInterval"><see cref="ElasticsearchSinkOptions.BufferLogShippingInterval"/></param>
Expand All @@ -89,7 +94,8 @@ public static LoggerConfiguration Elasticsearch(
string bufferBaseFilename = null,
long? bufferFileSizeLimitBytes = null,
long bufferLogShippingInterval = 5000,
string connectionGlobalHeaders = null)
string connectionGlobalHeaders = null,
LoggingLevelSwitch loggingLevelSwitch = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other public APIs exposed by Serilog, we call this levelSwitch - would be good to be consistent (if this change is accepted).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will align.

{
if (string.IsNullOrEmpty(nodeUris))
throw new ArgumentNullException("nodeUris", "No Elasticsearch node(s) specified.");
Expand Down Expand Up @@ -119,7 +125,8 @@ public static LoggerConfiguration Elasticsearch(
options.BatchPostingLimit = batchPostingLimit;
options.Period = TimeSpan.FromSeconds(period);
options.InlineFields = inlineFields;
options.MinimumLogEventLevel = restrictedToMinimumLevel;
options.MinimumLogEventLevel = restrictedToMinimumLevel;
options.LoggingLevelSwitch = loggingLevelSwitch;

if (!string.IsNullOrWhiteSpace(bufferBaseFilename))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ public class ElasticsearchSinkOptions
public bool InlineFields { get; set; }

/// <summary>
/// The minimum log event level required in order to write an event to the sink.
/// The minimum log event level required in order to write an event to the sink. Ignored when LoggingLevelSwitch is specified.
/// </summary>
public LogEventLevel? MinimumLogEventLevel { get; set; }

/// <summary>
/// A switch allowing the pass-through minimum level to be changed at runtime.
/// </summary>
public LoggingLevelSwitch LoggingLevelSwitch { get; set; }

///<summary>
/// When passing a serializer unknown object will be serialized to object instead of relying on their ToString representation
/// </summary>
Expand Down