I'm trying to work out how to test that a message and log level are correct in my Serilog logging library.
I am using the Serilog.Sinks.TextWriter
which gives me the output from Serilog as a string
and when I print to the console I get these lines:
[16:44:03 INF] hello // actual log
2020-09-08 16:44:03.117 +01:00 [Information] hello // from StringWriter
I have this incomplete method:
[Fact]
public void LogInfo_InfoOutputCorrect()
{
var logger = new Logger();
const string message = "Test Info Log Output";
const string level = "[Information]";
logger.LogInfo(message); // log info method
string returnMessage = logger.LogMessages(); // string from StringWriter
}
The message from the second line above I was thinking I could use the Contains
string method to see if the message and log level match.
returnMessage.Contains(level) && returnMessage.Contains(message)
But not sure how to do this.