Skip to content
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

Sink wrapping #955

Merged
merged 4 commits into from Apr 2, 2017
Merged
Diff settings

Always

Just for now

@@ -150,6 +150,29 @@ internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action
{
if (logger == null) throw new ArgumentNullException(nameof(logger));
return Sink(new SecondaryLoggerSink(logger, attemptDispose: false), restrictedToMinimumLevel);
}
}

/// <summary>
/// Helper method for wrapping sinks.
/// </summary>
/// <param name="logggerSinkConfiguration">The parent sink configuration.</param>

This comment has been minimized.

Copy link
@nblumhardt

nblumhardt Mar 30, 2017

Member

ggg

/// <param name="sinkDecorator">A function that allows for wrapping <see cref="ILogEventSink"/>s

This comment has been minimized.

Copy link
@nblumhardt

nblumhardt Mar 30, 2017

Member

Since it's an action, and the API uses the term wrap rather than decorate, could we use wrapSink? Also missing a period/full-stop for this sentence.

/// added in <paramref name="sinkConfigurationAction"/></param>
/// <param name="sinkConfigurationAction">An action that configures sinks to be wrapped in <paramref name="sinkDecorator"/></param>
/// <returns>Configuration object allowing method chaining.</returns>
public static LoggerConfiguration Wrap(
LoggerSinkConfiguration logggerSinkConfiguration,
Func<ILogEventSink, ILogEventSink> sinkDecorator,
Action<LoggerSinkConfiguration> sinkConfigurationAction)

This comment has been minimized.

Copy link
@nblumhardt

nblumhardt Mar 30, 2017

Member

Ditto here, could be configureWrappedSink.

{
var capturingLoggerSinkConfiguration = new LoggerSinkConfiguration(

This comment has been minimized.

Copy link
@nblumhardt

nblumhardt Mar 30, 2017

Member

Missing argument null checks.

logggerSinkConfiguration._loggerConfiguration,
s => logggerSinkConfiguration.Sink(sinkDecorator(s)),
logggerSinkConfiguration._applyInheritedConfiguration);

sinkConfigurationAction(capturingLoggerSinkConfiguration);

return logggerSinkConfiguration._loggerConfiguration;
}
}
}
@@ -10,6 +10,7 @@
using Serilog.Core.Filters;
using Serilog.Events;
using Serilog.Tests.Support;
using TestDummies;

namespace Serilog.Tests
{
@@ -577,5 +578,19 @@ public string Property
get { throw new Exception("Boom!"); }
}
}

[Fact]
public void WrappedSinks()

This comment has been minimized.

Copy link
@nblumhardt

nblumhardt Mar 30, 2017

Member

WrappingDecoratesTheConfiguredSink()?

{
var sink = new CollectingSink();
var logger = new LoggerConfiguration()
.WriteTo.DummyWrapping(w => w.Sink(sink))
.CreateLogger();

logger.Write(Some.InformationEvent());

Assert.NotEmpty(DummyWrappingSink.Emitted);
Assert.NotEmpty(sink.Events);
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Serilog;
using Serilog.Events;
using Serilog.Formatting;
@@ -42,5 +41,15 @@ public static LoggerConfiguration WithDummyThreadId(this LoggerEnrichmentConfigu
{
return loggerSinkConfiguration.Sink(new DummyRollingFileAuditSink(), restrictedToMinimumLevel);
}

public static LoggerConfiguration DummyWrapping(

This comment has been minimized.

Copy link
@nblumhardt

nblumhardt Mar 30, 2017

Member

WriteTo.Dummy()? :-)

this LoggerSinkConfiguration loggerSinkConfiguration,
Action<LoggerSinkConfiguration> wrappedSinkAction)
{
return LoggerSinkConfiguration.Wrap(
loggerSinkConfiguration,
s => new DummyWrappingSink(s),
wrappedSinkAction);
}
}
}
@@ -0,0 +1,26 @@
using System;
using Serilog.Core;
using Serilog.Events;
using System.Collections.Generic;

namespace TestDummies
{
public class DummyWrappingSink : ILogEventSink
{
[ThreadStatic]
public static List<LogEvent> Emitted = new List<LogEvent>();

private readonly ILogEventSink _sink;

public DummyWrappingSink(ILogEventSink sink)
{
_sink = sink;
}

public void Emit(LogEvent logEvent)
{
Emitted.Add(logEvent);
_sink.Emit(logEvent);
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.