private static void LogTest()
 {
     var logger = new NLogLogger(new ApplicationSettings());
     logger.Debug("Just testing debug", "Debug");
     logger.Info("Just testing info", "Info");
     logger.Warn("Just testing warning", "Warning");
     logger.Error("Just testing error", "Error");
     logger.Fatal("Testing with exception", new Exception("TestException"), "Some details again");
 }
        public void GetLogItems_AddedOneLogItem_ContainsOneLogItem()
        {
            var logRepository = new LogRepository(Session);
            var logger = new NLogLogger(DefaultTestApplicationSettings);
            var gridSettings = new GridSettings { PageSize = 10, PageIndex = 0 };

            const string message = "Test";
            logger.Debug(message);

            var logItems = logRepository.GetLogItems(gridSettings);

            Assert.AreEqual(1, logItems.Count);
            Assert.AreEqual(message, logItems[0].Message);
        }
        public void CountLogItems_AddedTenLogItems_CollectionContainsTenLogItems()
        {
            var logRepository = new LogRepository(Session);
            var logger = new NLogLogger(DefaultTestApplicationSettings);
            var gridSettings = new GridSettings { PageSize = 20, PageIndex = 0 };

            const int totalMessages = 10;

            for (var messageCounter = 0; messageCounter < totalMessages; messageCounter++)
            {
                logger.Debug("Test");
            }

            var logItems = logRepository.GetLogItems(gridSettings);

            Assert.AreEqual(10, logItems.Count);
        }
        public void WhenNoCurrentClassNameIsSpecifiedNLogUsesDefaultCurrentClassName()
        {
            var logger = new NLogLogger(new TestApplicationSettings());

            var logMessageId = logger.Debug("This is a log message", "Some extra log details");

            var logMessage = GetLogMessageFromDatabase(logMessageId);

            Assert.AreEqual("Infrastructure.Loggers.NLogLogger", logMessage.Source);
        }
        public void NullableValuesInHttpContextDoNotBreakLogging()
        {
            // Set nullable values is true to set user to null and urlreferrer to null.
            var logger = new NLogLogger(new TestApplicationSettings(), "NLogLoggerTests", GetHttpContext(nullValues: true));

            var logMessageId = logger.Debug("This is a log message");

            var logMessage = GetLogMessageFromDatabase(logMessageId);

            Assert.AreEqual(string.Empty, logMessage.Username);
            Assert.AreEqual(string.Empty, logMessage.UrlReferrer);
        }