コード例 #1
0
        public void CanWriteToDatabase()
        {
            // Arrange
            ILog log = LogManager.GetLogger(rep.Name, "CanWriteToDatabase");

            // Act
            log.Error(ErrorMessage);
            Thread.Sleep(200); // let background thread finish

            // Assert
            bool isLogEntryPresent = LogsDBAccess.IsLogEntryPresent(ErrorLevel, ErrorMessage, ApplicationName);

            Assert.That(isLogEntryPresent, Is.True);
        }
コード例 #2
0
        public void ReturnsQuicklyAfterLogging100Messages()
        {
            // Arrange
            ILog log = LogManager.GetLogger(rep.Name, "ReturnsQuicklyAfterLogging100Messages");

            // Act
            DateTime startTime = DateTime.UtcNow;

            100.Times(i => log.Error(ErrorMessage));
            DateTime endTime = DateTime.UtcNow;

            // Give background thread time to finish
            Thread.Sleep(500);

            // Assert
            Assert.That(endTime - startTime, Is.LessThan(TimeSpan.FromMilliseconds(100)));
            int logCount = LogsDBAccess.CountLogEntriesPresent(ErrorLevel, ErrorMessage, ApplicationName);

            Assert.That(logCount, Is.EqualTo(100));
        }
コード例 #3
0
        public void TestFixtureSetUp()
        {
            appender = new AsyncAdoAppender
            {
                CommandType      = CommandType.Text,
                ConnectionString = connectionString,
                CommandText      = commandText,
                ConnectionType   = connectionType
            };

            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.DateTime, ParameterName = "@log_date", Layout = new RawUtcTimeStampLayout()
            });
            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.String, Size = 255, ParameterName = "@thread", Layout = new Layout2RawLayoutAdapter(new PatternLayout("%thread"))
            });
            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.String, Size = 40, ParameterName = "@log_level", Layout = new Layout2RawLayoutAdapter(new PatternLayout("%level"))
            });
            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.String, Size = 255, ParameterName = "@logger", Layout = new Layout2RawLayoutAdapter(new PatternLayout("%logger"))
            });
            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.String, Size = 4000, ParameterName = "@message", Layout = new Layout2RawLayoutAdapter(new PatternLayout("%message"))
            });
            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.String, Size = 4000, ParameterName = "@exception", Layout = new Layout2RawLayoutAdapter(new PatternLayout("%exception"))
            });
            appender.AddParameter(new AdoNetAppenderParameter {
                DbType = DbType.String, Size = 200, ParameterName = "@application", Layout = new Layout2RawLayoutAdapter(new PatternLayout(ApplicationName))
            });

            appender.Threshold  = ErrorLevel;
            appender.BufferSize = -1;
            appender.ActivateOptions();

            rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
            BasicConfigurator.Configure(rep, appender);
            LogsDBAccess.RemoveMatchingLogEntries(ErrorLevel, ErrorMessage, ApplicationName);
        }
コード例 #4
0
        public void CanLogAtleast1000MessagesASecond()
        {
            // Arrange
            ILog log = LogManager.GetLogger(rep.Name, "CanLogAtLeast1000MessagesASecond");

            int  logCount    = 0;
            bool logging     = true;
            bool logsCounted = false;

            var logTimer = new Timer(s =>
            {
                logging     = false;
                logCount    = LogsDBAccess.CountLogEntriesPresent(ErrorLevel, ErrorMessage, ApplicationName);
                logsCounted = true;
            }, null, TimeSpan.FromSeconds(3), TimeSpan.FromMilliseconds(-1));

            // Act
            DateTime startTime = DateTime.UtcNow;

            while (logging)
            {
                log.Error(ErrorMessage);
            }
            TimeSpan testDuration = DateTime.UtcNow - startTime;

            while (!logsCounted)
            {
                Thread.Sleep(1);
            }

            logTimer.Dispose();

            // Assert
            var logsPerSecond = logCount / testDuration.TotalSeconds;

            Console.WriteLine("{0} messages logged in {1}s => {2}/s", logCount, testDuration.TotalSeconds, logsPerSecond);
            Assert.That(logsPerSecond, Is.GreaterThan(1000), "Must log at least 1000 messages per second");
        }
コード例 #5
0
 public void TestFixtureTearDown()
 {
     LogsDBAccess.RemoveMatchingLogEntries(ErrorLevel, ErrorMessage, ApplicationName);
     rep.Shutdown();
 }