public async Task SimpleWrite()
        {
            var processor         = new ConsoleLogProcessor();
            var defaultConsoleOut = Console.Out;

            await using var stream = new MemoryStream();

            await using (var writer = new StreamWriter(stream, leaveOpen: true))
            {
                Console.SetOut(writer);

                foreach (var message in _messages)
                {
                    processor.EnqueueMessage(message);
                }

                var complexMessage = CreateQueueItems("test 1");

                processor.EnqueueMessage(complexMessage);

                await Task.Delay(1000);
            }

            var standardOutput = new StreamWriter(Console.OpenStandardOutput())
            {
                AutoFlush = true
            };

            Console.SetOut(standardOutput);

            stream.Position = 0;

            List <string> log = new List <string>();

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    log.Add(await reader.ReadLineAsync());
                }
            }

            Assert.AreEqual(log[0], "first message");
            Assert.AreEqual(log[1], "second message");
            Assert.AreEqual(log[2], "third message");
            Assert.AreEqual(log[3], "test 1 first part");
            Assert.AreEqual(log[4], "test 1 second part");
            Assert.AreEqual(log[5], "test 1 third part");
        }
        public async Task ConcurrentWriteWrite()
        {
            var processor         = new ConsoleLogProcessor();
            var defaultConsoleOut = Console.Out;

            await using var stream = new MemoryStream();

            await using (var writer = new StreamWriter(stream, leaveOpen: true))
            {
                Console.SetOut(writer);

                List <Task> tasks = new List <Task>();

                var letters = "ABCDEFGHJKLMNOP";

                for (int i = 0; i < 10; i++)
                {
                    var i1   = i;
                    var task = Task.Factory.StartNew(() =>
                    {
                        var message = CreateQueueItems(letters[i1].ToString(), 20);
                        processor.EnqueueMessage(message);
                    });

                    tasks.Add(task);
                }

                await Task.Delay(1000);
            }

            var standardOutput = new StreamWriter(Console.OpenStandardOutput())
            {
                AutoFlush = true
            };

            Console.SetOut(standardOutput);

            stream.Position = 0;

            List <string> log = new List <string>();

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    log.Add(await reader.ReadLineAsync());
                }
            }

            for (int m = 0; m < 10; m++)
            {
                var letter = log[m * 21][0];

                for (int l = 0; l < 20; l++)
                {
                    var index = m * 21 + l;
                    Assert.AreEqual(log[index], $"{letter} {l+1}'st part");
                }
            }
        }
Beispiel #3
0
        public void Log(SemanticLogLevel logLevel, string message)
        {
            var color = 0;

            if (logLevel == SemanticLogLevel.Warning)
            {
                color = 0xffff00;
            }
            else if (logLevel >= SemanticLogLevel.Error)
            {
                color = 0xff0000;
            }

            processor.EnqueueMessage(new LogMessageEntry {
                Message = message, Color = color
            });
        }
Beispiel #4
0
 public void Log(SemanticLogLevel logLevel, string message)
 {
     processor.EnqueueMessage(new LogMessageEntry {
         Message = message, Level = logLevel
     });
 }
Beispiel #5
0
 public void Log(SemanticLogLevel logLevel, string message)
 {
     processor.EnqueueMessage(new LogMessageEntry {
         Message = message, IsError = logLevel >= SemanticLogLevel.Error
     });
 }