Inheritance: LoggerBase
Example #1
0
        public void SqlLoggerInvalidConnectionStringProcedure()
        {
            DateTime testStart = DateTime.Now;

            Log.DefaultMemoryLogger.ValidLevels = LogLevels.All;

            // Create a new SQL logger
            SqlLogger sqlLogger = new SqlLogger("Test SQL Logger", Guid.NewGuid(), ConnectionStringInvalid);

            // Add the SQL logger
            Log.GetOrAddLogger(sqlLogger);

            AddTestLogItems(testStart);

            Thread.Sleep(15000);

            // Now retrieve the logs.
            IEnumerable<Log> logs = Log.GetForward(testStart, 10);

            Assert.IsTrue(
                    logs.Any(l => l.Level == LogLevel.Critical) &&
                    logs.Any(
                            l =>
                            l.Level == LogLevel.Information && l.ExceptionType != null &&
                            l.ExceptionType.Equals("System.Data.SqlClient.SqlException")));
        }
Example #2
0
        public void TestSqlLogger()
        {
            DateTime testStart = DateTime.Now;

            Log.DefaultMemoryLogger.ValidLevels = LogLevels.All;

            // Create a new SQL logger
            SqlLogger sqlLogger = new SqlLogger("Test SQL Logger", 
                new Guid("E12A1F4A-6F69-4F35-B2A0-96B112C495D5"), 
                ConnectionString);

            // Add the SQL logger
            Log.GetOrAddLogger(sqlLogger);

            // Every 500ms log some items.
            int x = 0;
            while (x < 50)
            {
                AddTestLogItemsWrapper(testStart);
                x++;

                Thread.Sleep(500);
            }

            // TODO: Retrieve and check we havent added the latest every time.
            
            //foreach (string expectedOutput in testLogItems.Select(test => test.ExpectedOutput))
            //{
            //    string output = expectedOutput;
            //    Assert.IsTrue(logs.Any(l => l.Operation.Name == OPERATION_NAME
            //        && l.Operation.CategoryName == OPERATION_CATEGORY_NAME
            //        && l.Operation.Parent != null
            //        && l.Operation.Parent.Name == OPERATION_NAME_WRAPPER
            //        && l.Message.Equals(output)));
            //}
        }
Example #3
0
        public void TestSqlLoggerMemoryCacheExpired()
        {
            DateTime testStart = DateTime.Now;

            Log.DefaultMemoryLogger.ValidLevels = LogLevels.All;

            // Create a new sql logger
            SqlLogger sqlLogger = new SqlLogger("Test SQL Logger",
                new Guid("E12A1F4A-6F69-4F35-B2A0-96B112C495D5"),
                ConnectionString);

            // Add the sql logger
            Log.GetOrAddLogger(sqlLogger);

            // Add the test log items
            var testLogItems = AddTestLogItemsWrapper(testStart);

            Thread.Sleep(2100000);

            // Force an immediate GC of all generations.
            GC.Collect(0, GCCollectionMode.Forced);
            GC.Collect(1, GCCollectionMode.Forced);
            GC.Collect(2, GCCollectionMode.Forced);

            // Give the GC 120s econds (just to be safe).
            Thread.Sleep(120000);

            IEnumerable<Log> logs = Log.GetForward(sqlLogger, testStart, 10);

            //foreach (string expectedOutput in testLogItems.Select(test => test.ExpectedOutput))
            //{
            //    string output = expectedOutput;
            //    Assert.IsTrue(logs.Any(l => l.Operation.Name == OPERATION_NAME
            //        && l.Operation.CategoryName == OPERATION_CATEGORY_NAME
            //        && l.Operation.Parent != null
            //        && l.Operation.Parent.Name == OPERATION_NAME_WRAPPER
            //        && l.Message.Equals(output)));
            //}
        }
Example #4
0
        public void SqlLoggerInvalidGetStoredProcedure()
        {
            DateTime testStart = DateTime.Now;

            Log.DefaultMemoryLogger.ValidLevels = LogLevels.All;

            // Create a new SQL logger
            SqlLogger sqlLogger = new SqlLogger(
                    "Test SQL Logger", Guid.NewGuid(), ConnectionString, getStoredProcedure: Guid.NewGuid().ToString());

            // Add the SQL logger
            Log.GetOrAddLogger(sqlLogger);

            AddTestLogItems(testStart);
        }