Skip to content

Commit

Permalink
removed inheriting minimum level from other places
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Komisarchik committed Aug 1, 2020
1 parent b60795c commit 89ec7f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/Serilog/Configuration/LoggerAuditSinkConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 Serilog Contributors
// Copyright 2016-2020 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,9 +25,9 @@ public class LoggerAuditSinkConfiguration
{
readonly LoggerSinkConfiguration _sinkConfiguration;

internal LoggerAuditSinkConfiguration(LoggerConfiguration loggerConfiguration, Action<ILogEventSink> addSink, Action<LoggerConfiguration> applyInheritedConfiguration)
internal LoggerAuditSinkConfiguration(LoggerConfiguration loggerConfiguration, Action<ILogEventSink> addSink)
{
_sinkConfiguration = new LoggerSinkConfiguration(loggerConfiguration, addSink, applyInheritedConfiguration);
_sinkConfiguration = new LoggerSinkConfiguration(loggerConfiguration, addSink);
}

/// <summary>
Expand Down
17 changes: 4 additions & 13 deletions src/Serilog/Configuration/LoggerSinkConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015 Serilog Contributors
// Copyright 2013-2020 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,13 +30,11 @@ public class LoggerSinkConfiguration
{
readonly LoggerConfiguration _loggerConfiguration;
readonly Action<ILogEventSink> _addSink;
readonly Action<LoggerConfiguration> _applyInheritedConfiguration;

internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action<ILogEventSink> addSink, Action<LoggerConfiguration> applyInheritedConfiguration)
internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action<ILogEventSink> addSink)
{
_loggerConfiguration = loggerConfiguration ?? throw new ArgumentNullException(nameof(loggerConfiguration));
_addSink = addSink ?? throw new ArgumentNullException(nameof(addSink));
_applyInheritedConfiguration = applyInheritedConfiguration ?? throw new ArgumentNullException(nameof(applyInheritedConfiguration));
}

/// <summary>
Expand Down Expand Up @@ -126,13 +124,7 @@ internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action
{
if (configureLogger == null) throw new ArgumentNullException(nameof(configureLogger));

var lc = new LoggerConfiguration();

// apply inherited configuration except minimum level
// since parent logger can have overrides
_applyInheritedConfiguration(lc);
lc.MinimumLevel.Is(LevelAlias.Minimum);

var lc = new LoggerConfiguration().MinimumLevel.Is(LevelAlias.Minimum);
configureLogger(lc);

var subLogger = lc.CreateLogger();
Expand Down Expand Up @@ -241,8 +233,7 @@ public LoggerConfiguration Conditional(Func<LogEvent, bool> condition, Action<Lo
var capturingConfiguration = new LoggerConfiguration();
var capturingLoggerSinkConfiguration = new LoggerSinkConfiguration(
capturingConfiguration,
sinksToWrap.Add,
loggerSinkConfiguration._applyInheritedConfiguration);
sinksToWrap.Add);

// `WriteTo.Sink()` will return the capturing configuration; this ensures chained `WriteTo` gets back
// to the capturing sink configuration, enabling `WriteTo.X().WriteTo.Y()`.
Expand Down
14 changes: 3 additions & 11 deletions src/Serilog/LoggerConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2016 Serilog Contributors
// Copyright 2013-2020 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,18 +48,10 @@ public class LoggerConfiguration
/// </summary>
public LoggerConfiguration()
{
WriteTo = new LoggerSinkConfiguration(this, s => _logEventSinks.Add(s), ApplyInheritedConfiguration);
WriteTo = new LoggerSinkConfiguration(this, s => _logEventSinks.Add(s));
Enrich = new LoggerEnrichmentConfiguration(this, e => _enrichers.Add(e));
}

void ApplyInheritedConfiguration(LoggerConfiguration child)
{
if (_levelSwitch != null)
child.MinimumLevel.ControlledBy(_levelSwitch);
else
child.MinimumLevel.Is(_minimumLevel);
}

/// <summary>
/// Configures the sinks that log events will be emitted to.
/// </summary>
Expand All @@ -76,7 +68,7 @@ void ApplyInheritedConfiguration(LoggerConfiguration child)
/// extending <see cref="LoggerAuditSinkConfiguration"/>, though the generic <see cref="LoggerAuditSinkConfiguration.Sink"/>
/// method allows any sink class to be adapted for auditing.
/// </remarks>
public LoggerAuditSinkConfiguration AuditTo => new LoggerAuditSinkConfiguration(this, s => _auditSinks.Add(s), ApplyInheritedConfiguration);
public LoggerAuditSinkConfiguration AuditTo => new LoggerAuditSinkConfiguration(this, s => _auditSinks.Add(s));

/// <summary>
/// Configures the minimum level at which events will be passed to sinks. If
Expand Down

0 comments on commit 89ec7f3

Please sign in to comment.