コード例 #1
0
        public void CanWriteToLogFile()
        {
            FileExceptionlessLog log = GetLog(LOG_FILE);

            log.Info("Test");
            log.Flush();

            Assert.True(LogExists());
            string contents = GetLogContent();

            Assert.Equal("Test\r\n", contents);

            log.Dispose();
        }
コード例 #2
0
        public virtual void CanWriteToLogFile()
        {
            DeleteLog();

            using (FileExceptionlessLog log = GetLog(LOG_FILE)) {
                log.Info("Test");
                log.Flush();

                Assert.True(LogExists());
                string contents = log.GetFileContents();

                Assert.Equal("Test\r\n", contents);
            }
        }
コード例 #3
0
        public virtual void LogFlushTimerWorks()
        {
            DeleteLog();

            using (FileExceptionlessLog log = GetLog(LOG_FILE)) {
                log.Info("Test");

                string contents = log.GetFileContents();
                Assert.Equal("", contents);

                Thread.Sleep(1010 * 3);

                Assert.True(LogExists());
                contents = log.GetFileContents();

                Assert.Equal("Test\r\n", contents);
            }
        }
コード例 #4
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();
        }
コード例 #5
0
        public void LogFlushTimerWorks()
        {
            DeleteLog();

            FileExceptionlessLog log = GetLog(LOG_FILE);

            log.Info("Test");

            string contents = GetLogContent();

            Assert.Equal("", contents);

            Thread.Sleep(1010 * 3);

            Assert.True(LogExists());
            contents = GetLogContent();

            Assert.Equal("Test\r\n", contents);

            log.Dispose();
        }
コード例 #6
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();
        }
コード例 #7
0
        public void CheckSizeDoesNotFailIfLogIsMissing()
        {
            FileExceptionlessLog log = GetLog(LOG_FILE + ".doesnotexist");

            log.CheckFileSize();
        }