Skip to content

Commit

Permalink
Reinstate LoggerSinkConfiguration.Sink(ILogEventSink, LogEventLevel) (
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Mar 30, 2023
1 parent 8bb02df commit 883e208
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Build.ps1
Expand Up @@ -32,4 +32,8 @@ Write-Output "build: Testing"

& dotnet test test\Serilog.Tests --configuration Release --no-build --no-restore

if($LASTEXITCODE -ne 0) { throw 'tests failed' }
if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }

& dotnet test test\Serilog.ApprovalTests --configuration Release --no-build --no-restore

if($LASTEXITCODE -ne 0) { throw 'approval tests failed' }
20 changes: 20 additions & 0 deletions src/Serilog/Configuration/LoggerSinkConfiguration.cs
Expand Up @@ -28,6 +28,23 @@ internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action
_addSink = Guard.AgainstNull(addSink);
}

/// <summary>
/// Write log events to the specified <see cref="ILogEventSink"/>.
/// </summary>
/// <param name="logEventSink">The sink.</param>
/// <param name="restrictedToMinimumLevel">The minimum level for
/// events passed through the sink.</param>
/// <seealso cref="Sink(ILogEventSink, LogEventLevel, LoggingLevelSwitch?)"/>
/// <returns>Configuration object allowing method chaining.</returns>
/// <remarks>Sink configuration methods that specify <paramref name="restrictedToMinimumLevel"/> should also specify <see cref="LoggingLevelSwitch"/>.</remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public LoggerConfiguration Sink(
ILogEventSink logEventSink,
LogEventLevel restrictedToMinimumLevel)
{
return Sink(logEventSink, restrictedToMinimumLevel, null);
}

/// <summary>
/// Write log events to the specified <see cref="ILogEventSink"/>.
/// </summary>
Expand All @@ -40,6 +57,9 @@ internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action
public LoggerConfiguration Sink(
ILogEventSink logEventSink,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
// The warning here is redundant; the optional parameter allows `WriteTo.Sink(s)` usage. We would obsolete the two-argument
// version above for purposes of economy, but end-user `WriteTo.Sink(s, level)` is valid and shouldn't result in a warning.
// ReSharper disable once MethodOverloadWithOptionalParameter
LoggingLevelSwitch? levelSwitch = null)
{
var sink = logEventSink;
Expand Down
7 changes: 6 additions & 1 deletion test/Serilog.ApprovalTests/ApiApprovalTests.cs
Expand Up @@ -16,6 +16,11 @@ public void PublicApi_Should_Not_Change_Unintentionally()
ExcludeAttributes = new[] { "System.Diagnostics.DebuggerDisplayAttribute" },
});

publicApi.ShouldMatchApproved(options => options.WithFilenameGenerator((_, _, fileType, fileExtension) => $"{assembly.GetName().Name!}.{fileType}.{fileExtension}"));
publicApi.ShouldMatchApproved(options =>
{
// Comment this line out to view the failure as a diff. Leave it here so that CI builds don't hang when this test fails.
options.NoDiff();
options.WithFilenameGenerator((_, _, fileType, fileExtension) => $"{assembly.GetName().Name!}.{fileType}.{fileExtension}");
});
}
}
8 changes: 4 additions & 4 deletions test/Serilog.ApprovalTests/Serilog.approved.txt
Expand Up @@ -70,6 +70,7 @@ namespace Serilog.Configuration
public Serilog.LoggerConfiguration Conditional(System.Func<Serilog.Events.LogEvent, bool> condition, System.Action<Serilog.Configuration.LoggerSinkConfiguration> configureSink) { }
public Serilog.LoggerConfiguration Logger(Serilog.ILogger logger, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0) { }
public Serilog.LoggerConfiguration Logger(System.Action<Serilog.LoggerConfiguration> configureLogger, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, Serilog.Core.LoggingLevelSwitch? levelSwitch = null) { }
public Serilog.LoggerConfiguration Sink(Serilog.Core.ILogEventSink logEventSink, Serilog.Events.LogEventLevel restrictedToMinimumLevel) { }
public Serilog.LoggerConfiguration Sink(Serilog.Core.ILogEventSink logEventSink, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, Serilog.Core.LoggingLevelSwitch? levelSwitch = null) { }
public Serilog.LoggerConfiguration Sink<TSink>(Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, Serilog.Core.LoggingLevelSwitch? levelSwitch = null)
where TSink : Serilog.Core.ILogEventSink, new () { }
Expand Down Expand Up @@ -823,14 +824,13 @@ namespace Serilog.Parsing
}
public abstract class MessageTemplateToken
{
protected MessageTemplateToken(int startIndex) { }
protected MessageTemplateToken() { }
public abstract int Length { get; }
public int StartIndex { get; }
public abstract void Render(System.Collections.Generic.IReadOnlyDictionary<string, Serilog.Events.LogEventPropertyValue> properties, System.IO.TextWriter output, System.IFormatProvider? formatProvider = null);
}
public sealed class PropertyToken : Serilog.Parsing.MessageTemplateToken
{
public PropertyToken(string propertyName, string rawText, string? format = null, in Serilog.Parsing.Alignment? alignment = null, Serilog.Parsing.Destructuring destructuring = 0, int startIndex = -1) { }
public PropertyToken(string propertyName, string rawText, string? format = null, in Serilog.Parsing.Alignment? alignment = null, Serilog.Parsing.Destructuring destructuring = 0) { }
public Serilog.Parsing.Alignment? Alignment { get; }
public Serilog.Parsing.Destructuring Destructuring { get; }
public string? Format { get; }
Expand All @@ -845,7 +845,7 @@ namespace Serilog.Parsing
}
public sealed class TextToken : Serilog.Parsing.MessageTemplateToken
{
public TextToken(string text, int startIndex = -1) { }
public TextToken(string text) { }
public override int Length { get; }
public string Text { get; }
public override bool Equals(object? obj) { }
Expand Down

0 comments on commit 883e208

Please sign in to comment.