Skip to content

Commit

Permalink
Merge branch 'daveaglick-issue561' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Nov 20, 2015
2 parents 22e9da9 + 2e3470b commit 1218d62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Serilog/LoggerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class LoggerConfiguration
LogEventLevel _minimumLevel = LogEventLevel.Information;
LoggingLevelSwitch _levelSwitch;
int _maximumDestructuringDepth = 10;
bool _loggerCreated;

/// <summary>
/// Configures the sinks that log events will be emitted to.
Expand Down Expand Up @@ -124,6 +125,10 @@ public LoggerSettingsConfiguration ReadFrom
/// disposed.</remarks>
public ILogger CreateLogger()
{
if (_loggerCreated)
throw new InvalidOperationException($"CreateLogger was previously called and can only be called once.");
_loggerCreated = true;

if (!_logEventSinks.Any())
return new SilentLogger();

Expand Down
8 changes: 8 additions & 0 deletions test/Serilog.Tests/LoggerConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public void Dispose()
}
}

[Fact]
public void CreateLoggerThrowsIfCalledMoreThanOnce()
{
var loggerConfiguration = new LoggerConfiguration();
loggerConfiguration.CreateLogger();
Assert.Throws<InvalidOperationException>(() => loggerConfiguration.CreateLogger());
}

[Fact]
public void DisposableSinksAreDisposedAlongWithRootLogger()
{
Expand Down

0 comments on commit 1218d62

Please sign in to comment.