Exemplo n.º 1
0
        public void LogIsThreadSafe()
        {
            DeleteLog();

            FileExceptionlessLog log = GetLog(LOG_FILE);

            // write 3mb of content to the log in multiple threads
            Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024)));

            log.Flush();
            Assert.True(log.GetFileSize() > 1024 * 1024 * 3);

            // force a check file size call
            log.CheckFileSize();

            // make sure it didn't clear the log
            Assert.True(log.GetFileSize() > 1024 * 1024 * 3);

            // write another 3mb of content to the log
            Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024)));
            log.Flush();

            long size = log.GetFileSize();

            Console.WriteLine("File: " + size);

            // do the check size while writing to the log from multiple threads
            Parallel.Invoke(
                () => Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024))),
                () => {
                Thread.Sleep(10);
                log.CheckFileSize();
            });

            // should be more than 99 lines of text in the file
            size = log.GetFileSize();
            Console.WriteLine("File: " + size);
            Assert.True(size > 1024 * 99);

            log.Dispose();
        }
Exemplo n.º 2
0
        public void LogResetsAfter5mb()
        {
            DeleteLog();

            FileExceptionlessLog log = GetLog(LOG_FILE);

            // write 3mb of content to the log
            for (int i = 0; i < 1024 * 3; i++)
            {
                log.Info(new string('0', 1024));
            }

            log.Flush();
            Assert.True(log.GetFileSize() > 1024 * 1024 * 3);

            // force a check file size call
            log.CheckFileSize();

            // make sure it didn't clear the log
            Assert.True(log.GetFileSize() > 1024 * 1024 * 3);

            // write another 3mb of content to the log
            for (int i = 0; i < 1024 * 3; i++)
            {
                log.Info(new string('0', 1024));
            }

            log.Flush();
            // force a check file size call
            log.CheckFileSize();

            // make sure it cleared the log
            long size = log.GetFileSize();

            // should be 99 lines of text in the file
            Assert.True(size > 1024 * 99);

            log.Dispose();
        }