-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from DbUp/enh-multipleLoggers286
Added the ability to specify multiple loggers.
- Loading branch information
Showing
9 changed files
with
165 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# 4.0.0 | ||
- If `builder.LogTo..()` is called multiple times, the logs are combined instead of replacing the previous logger | ||
- Default Encoding is now UTF rather than Encoding.Default | ||
- AdHocSqlRunner changed to use Expression<Func<>> rather than Func<> | ||
- AdHocSqlRunner changed to use Expression<Func<>> rather than Func<> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace DbUp.Engine.Output | ||
{ | ||
public class MultipleUpgradeLog : IUpgradeLog | ||
{ | ||
private readonly IUpgradeLog[] upgradeLogs; | ||
|
||
public MultipleUpgradeLog(params IUpgradeLog[] upgradeLogs) | ||
{ | ||
var otherMultipleLogs = upgradeLogs.OfType<MultipleUpgradeLog>().ToArray(); | ||
|
||
this.upgradeLogs = upgradeLogs | ||
.Except(otherMultipleLogs) | ||
.Concat(otherMultipleLogs.SelectMany(l => l.upgradeLogs)) | ||
.ToArray(); | ||
} | ||
|
||
public void WriteInformation(string format, params object[] args) | ||
{ | ||
foreach(var log in upgradeLogs) | ||
log.WriteInformation(format, args); | ||
} | ||
|
||
public void WriteError(string format, params object[] args) | ||
{ | ||
foreach (var log in upgradeLogs) | ||
log.WriteError(format, args); | ||
} | ||
|
||
public void WriteWarning(string format, params object[] args) | ||
{ | ||
foreach (var log in upgradeLogs) | ||
log.WriteWarning(format, args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using DbUp.Builder; | ||
using DbUp.Engine.Output; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace DbUp.Tests.Builder | ||
{ | ||
public class UpgradeConfigurationFixture | ||
{ | ||
[Fact] | ||
public void WhenNoLoggerIsAddedThenTheDefaultLoggerIsReturned() | ||
{ | ||
new UpgradeConfiguration() | ||
.Log.ShouldNotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void WhenASingleLoggerIsAddedThenItselfShouldBeReturned() | ||
{ | ||
var config = new UpgradeConfiguration(); | ||
var addedLog = new NoOpUpgradeLog(); | ||
config.AddLog(addedLog); | ||
config.Log.ShouldBe(addedLog); | ||
} | ||
|
||
[Fact] | ||
public void WhenMultipleLoggersAreAddedThenAMultipleLoggerShouldBeReturnedAndLogsGoToAllDestinations() | ||
{ | ||
var log1 = new TestLog(); | ||
var log2 = new TestLog(); | ||
var log3 = new TestLog(); | ||
|
||
var config = new UpgradeConfiguration(); | ||
config.AddLog(log1); | ||
config.AddLog(log2); | ||
config.AddLog(log3); | ||
config.Log.WriteInformation("Test"); | ||
|
||
config.Log.ShouldBeOfType<MultipleUpgradeLog>(); | ||
log1.WasWritten.ShouldBe(true); | ||
log2.WasWritten.ShouldBe(true); | ||
log3.WasWritten.ShouldBe(true); | ||
} | ||
|
||
[Fact] | ||
public void WhenTheLoggerIsClearedThenTheDefaultLoggerReturns() | ||
{ | ||
var config = new UpgradeConfiguration(); | ||
var defaultLog = config.Log; | ||
config.AddLog(new NoOpUpgradeLog()); | ||
config.Log.ShouldNotBe(defaultLog); | ||
|
||
config.Log = null; | ||
config.Log.ShouldBe(defaultLog); | ||
|
||
} | ||
|
||
class TestLog : IUpgradeLog | ||
{ | ||
public bool WasWritten { get; private set; } | ||
public void WriteInformation(string format, params object[] args) | ||
{ | ||
WasWritten = true; | ||
} | ||
|
||
public void WriteError(string format, params object[] args) | ||
{ | ||
WasWritten = true; | ||
} | ||
|
||
public void WriteWarning(string format, params object[] args) | ||
{ | ||
WasWritten = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters