Skip to content

Commit

Permalink
Merge pull request #202 from almostchristian/support-auditto-logger
Browse files Browse the repository at this point in the history
Support AuditTo.Logger
  • Loading branch information
nblumhardt authored Nov 21, 2019
2 parents 71839b8 + 0140f73 commit 02d559c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ static LoggerConfiguration Sink(
LoggingLevelSwitch levelSwitch = null)
=> auditSinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);

static LoggerConfiguration Logger(
LoggerAuditSinkConfiguration auditSinkConfiguration,
Action<LoggerConfiguration> configureLogger,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
LoggingLevelSwitch levelSwitch = null)
=> auditSinkConfiguration.Logger(configureLogger, restrictedToMinimumLevel, levelSwitch);

// .Filter...
// =======
// TODO: add overload for array argument (ILogEventEnricher[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,37 @@ public void AuditSinksAreConfigured()
Assert.Equal(1, DummyRollingFileAuditSink.Emitted.Count);
}

[Fact]
public void AuditToSubLoggersAreConfigured()
{
var json = @"{
""Serilog"": {
""Using"": [""TestDummies""],
""AuditTo"": [{
""Name"": ""Logger"",
""Args"": {
""configureLogger"" : {
""AuditTo"": [{
""Name"": ""DummyRollingFile"",
""Args"": {""pathFormat"" : ""C:\\""}
}]}
}
}]
}
}";

var log = ConfigFromJson(json)
.CreateLogger();

DummyRollingFileSink.Reset();
DummyRollingFileAuditSink.Reset();

log.Write(Some.InformationEvent());

Assert.Equal(0, DummyRollingFileSink.Emitted.Count);
Assert.Equal(1, DummyRollingFileAuditSink.Emitted.Count);
}

[Fact]
public void TestMinimumLevelOverrides()
{
Expand Down

0 comments on commit 02d559c

Please sign in to comment.