forked from serilog/serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
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 serilog#758 from nblumhardt/f-selflog-action
Enable(action) for SelfLog
- Loading branch information
Showing
2 changed files
with
93 additions
and
8 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
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Serilog.Debugging; | ||
using Xunit; | ||
|
||
namespace Serilog.Tests.Debugging | ||
{ | ||
public class SelfLogTests | ||
{ | ||
[ThreadStatic] | ||
static List<string> Messages; | ||
|
||
[Fact] | ||
public void MessagesAreWrittenWhenOutputIsSet() | ||
{ | ||
Messages = new List<string>(); | ||
SelfLog.Enable(m => | ||
{ | ||
Messages = Messages ?? new List<string>(); | ||
Messages.Add(m); | ||
}); | ||
|
||
SelfLog.WriteLine("Hello {0} {1} {2}", 0, 1, 2); | ||
Assert.True(Messages.Any(m => m.EndsWith("Hello 0 1 2"))); | ||
|
||
// Better to do this here than in another test, since at this point | ||
// we've confirmed there's actually something to disable. | ||
var count = Messages.Count; | ||
SelfLog.Disable(); | ||
SelfLog.WriteLine("Unwritten"); | ||
Assert.Equal(Messages.Count, count); | ||
} | ||
} | ||
} |