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();
        }
        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);
            }
        }
        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();
        }
        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();
        }