props/test/BanggoodShop.Tests/XUnitLogger.cs

33 lines
755 B
C#
Raw Normal View History

2021-05-11 06:52:57 +00:00
using System;
using SimpleLogger;
using Xunit.Abstractions;
namespace BanggoodShop
{
public class XUnitLogger : ILogReceiver
{
public LogLevel Level => LogLevel.Debug;
public string Identifier => GetType().Name;
private ITestOutputHelper outputHelper;
public XUnitLogger(ITestOutputHelper output)
{
this.outputHelper = output;
}
public void Flush()
{
}
public void LogMessage(string message, DateTime time, LogLevel level)
{
try
{
outputHelper.WriteLine($"[{time.ToShortTimeString()}][{level.ToString()}]: {message}");
}
catch (InvalidOperationException) { };
}
}
}