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.

            //Simple method to launch Windows' built in calculator application
            const string calculatorPath = C:\\Windows\\System32\\calc.exe";

            //Get an instance of EzProcess in order to create EzRoot.  Wrap it in a using statement to ensure that
            //.Dispose() is called
            using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
            {
                process.StartProcess();

                //Get the root element of the application
                EzRoot root = new EzRoot(process);

                //Create a new instance of EzLogMonitor
                EzLogMonitor logMonitor = new EzLogMonitor(process);

                //Create a list of messages to profile for
                List<string> watches = new List<string>
                {
                    "Test message 1",
                    "Test message 2"
                };

                //Start watching log output for Calculator for the watches item that was created above
                logMonitor.SyncWatchForOccurance(watches, 60, (messages, time) =>
                {
                    //First parameter -> list of all watches passed in initially
                    //Second parameter -> total profile time

                    //code that is run if none of the messages occur
                    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) =>
                {
                    //First parameter -> type of output; whether it was standard or error output
                    //Second parameter -> text within the watches which was matched
                    //Third parameter -> the full log message that the text was contained within
                    //Fourth parameter -> the amount of time into profiling that match occurred

                    //code that is run if one of the messages does occur
                    Console.WriteLine($"Text '{text}' occurred at {time} seconds into profiling.  " +
                        "Full message: {message}.  OutputType: {type}");
                });
            }