Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit cd177fb

Browse files
Log exception in XunitProvider (#668)
1 parent 03c5a54 commit cd177fb

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Microsoft.Extensions.Logging.Testing/XunitLoggerProvider.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Dispose()
3535

3636
public class XunitLogger : ILogger
3737
{
38-
private static readonly char[] NewLineChars = new[] { '\r', '\n' };
38+
private static readonly string[] NewLineChars = new[] { Environment.NewLine };
3939
private readonly string _category;
4040
private readonly LogLevel _minLogLevel;
4141
private readonly ITestOutputHelper _output;
@@ -55,13 +55,23 @@ public void Log<TState>(
5555
return;
5656
}
5757
var firstLinePrefix = $"| {_category} {logLevel}: ";
58-
var lines = formatter(state, exception).Split('\n');
59-
WriteLine(firstLinePrefix + lines.First().TrimEnd(NewLineChars));
58+
var lines = formatter(state, exception).Split(NewLineChars, StringSplitOptions.RemoveEmptyEntries);
59+
WriteLine(firstLinePrefix + lines.First());
6060

6161
var additionalLinePrefix = "|" + new string(' ', firstLinePrefix.Length - 1);
6262
foreach (var line in lines.Skip(1))
6363
{
64-
WriteLine(additionalLinePrefix + line.TrimEnd(NewLineChars));
64+
WriteLine(additionalLinePrefix + line);
65+
}
66+
67+
if (exception != null)
68+
{
69+
lines = exception.ToString().Split(NewLineChars, StringSplitOptions.RemoveEmptyEntries);
70+
additionalLinePrefix = "| ";
71+
foreach (var line in lines.Skip(1))
72+
{
73+
WriteLine(additionalLinePrefix + line);
74+
}
6575
}
6676
}
6777

0 commit comments

Comments
 (0)