EzLogMonitor
EzLogMonitor is a class that is used to monitor output of the application under test. It provides several methods to watch for log messages and to take action appropriately.
Note that tis class is somewhat complicated to use so be sure to check out the Samples and Usage section at the bottom.
Syntax
public class EzLogMonitor
Constructors
Name |
Input |
Description |
EzLogMonitor(EzProcess process, ILogMessageComparer comparer = null) |
EzProcess |
Creates a new instance of EzLogMonitor. An instance of EzProcess is needed |
Methods
Name |
Return Type |
Description |
SyncWatchForOccurance(IEnumerable<string> watches, int timeInSeconds, IfFailMultiple ifFail, IfSuccessSingular ifSuccess) |
void |
Starts a synchronous watch for a series of log messages. If the message does not occur, the ifFail delegate is called and if it does occur, the ifSuccess message is called |
SyncWatchForOccurance(string watchText, int timeInSeconds, IfFailNonOccurance ifFail, IfSuccessSingular ifSuccess) |
void |
Starts a synchronous watch for a single log message. If the message does not occur, the ifFail delegate is called and if it does occur, the ifSuccess message is called |
SyncWatchForNonOccurance(IEnumerable<string> watches, int timeInSeconds, IfFailSingular ifFail, IfSuccessMultiple ifSuccess) |
void |
Starts a synchronous watch for a series of log messages. If the message does occur, the ifFail delegate is called and if it does not occur, the ifSuccess message is called |
SyncWatchForNonOccurance(string watchText, int timeInSeconds, IfFailSingular ifFail, IfSuccessNonOccurance ifSuccess) |
void |
Starts a synchronous watch for a single log message. If the message does occur, the ifFail delegate is called and if it does not occur, the ifSuccess message is called |
Samples and Usage
This code sample shows a simple use case for creating multiple watches and having EazyE2E monitor the standard and error output logs for the messages.
const string calculatorPath = C:\\Windows\\System32\\calc.exe";
using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
{
process.StartProcess();
EzRoot root = new EzRoot(process);
EzLogMonitor logMonitor = new EzLogMonitor(process);
List<string> watches = new List<string>
{
"Test message 1",
"Test message 2"
};
logMonitor.SyncWatchForOccurance(watches, 60, (messages, time) =>
{
string allMessages = messages.Aggregate((a, b) => a + ", " + b);
Console.WriteLine($"Could not find any messages within watches: '{allMessages}' " +
"after {time} seconds of profiling");
},
(type, text, message, time) =>
{
Console.WriteLine($"Text '{text}' occurred at {time} seconds into profiling. " +
"Full message: {message}. OutputType: {type}");
});
}