Ejemplo n.º 1
0
        public void WriteExceptionWithExceptionAndTitleAndReferenceId()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            try
            {
                throw new ApplicationException("Oops");
            }
            catch (Exception ex)
            {
                logWriter.WriteException(ex, "WriteExceptionWithExceptionAndTitleAndReferenceId", "ExcRefID123");
                logWriter.Flush();
            }
        }
Ejemplo n.º 2
0
        public void WriteExceptionWithException()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            try
            {
                throw new ApplicationException("Oops");
            }
            catch (Exception ex)
            {
                logWriter.WriteException(ex);
            }

            logWriter.Flush();
        }
Ejemplo n.º 3
0
        public void WriteLogWithLevelEnabledThenDisabledCreatesSingleEntry()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("WriteLogWithLevelEnabledThenDisabledCreatesSingleEntry", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object, "WriteLogWithLevelEnabledThenDisabledCreatesSingleEntry");
            logWriter.WriteLog(LogSeverityType.Error, "WriteLogWithLevelEnabledThenDisabledShouldGenerateOneEntry", "Message text");

            string configXml = "<Config><LogLevel>Fatal</LogLevel></Config>";
              //  configManager.Setup(cm => cm.TryGetXML("EventLog", "WriteLogWithLevelEnabledThenDisabledCreatesSingleEntry", "1.0", out configXml)).Returns(true);

            const int MillisecondsPerSecond = 60000;
            const int SleepTimeMs = 250;
            const int ExtraSecondsToWait = 15;

            Assert.IsTrue(logWriter.IsDebugEnabled);

            // Wait for the timer to time out and reload the log level
            for (int x = 0; x < ((LogWriterBase.LogLevelTimeoutMins * MillisecondsPerSecond) / SleepTimeMs) + (4 * ExtraSecondsToWait); x++)
            {
                System.Windows.Forms.Application.DoEvents();
                Thread.Sleep(SleepTimeMs);
            }

            // Force immediate log level refresh
            //logWriter.RefreshActiveLogLevel();

            Assert.IsFalse(logWriter.IsDebugEnabled);

            logWriter.WriteLog(LogSeverityType.Error, "This should never be logged", "This should never be logged");

            logWriter.Flush();
        }
Ejemplo n.º 4
0
        private static void WriteThread()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object, "WriteThread");

            string threadId = Thread.CurrentThread.ManagedThreadId.ToString();
            string title = "WriteLogWithMultipleThreads (" + threadId + ")";

            for (int x = 0; x < 150; x++)
            {
                LogRecord r =
                    new LogRecord(LogSeverityType.Error, title + ":" + x.ToString(), "Message text")
                    {
                        AdditionalInfo1 = "AddlInfo1",
                        AdditionalInfo2 = "AddlInfo2",
                        AlertCondition = "Condition",
                        ReferenceId = "RefID123"
                    };

                logWriter.WriteLog(r);
            }
        }
Ejemplo n.º 5
0
        public void WriteSecurityActionWithActionNameAndDescriptionAndUserIdAndTargetAccount()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            logWriter.WriteSecurityActionLog("ForgotPassword_Success", "Action from unit test", "UnitTestUser", "ImpersonatedUser");
        }
Ejemplo n.º 6
0
        public void WriteXml()
        {
            string xml = File.ReadAllText("Sample.xml");

            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            logWriter.WriteXml("WriteXml", xml);
            logWriter.Flush();
        }
Ejemplo n.º 7
0
        public void WriteSecurityActionWithActionNameAndDescription()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            logWriter.WriteSecurityActionLog("ForgotPassword_Success", "Action from unit test");
        }
Ejemplo n.º 8
0
        public void WriteLogWithTwoLogWriters()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            LogRecord r =
                new LogRecord(LogSeverityType.Error, "WriteLogWithTwoLogWriters", "Message text")
                {
                    AdditionalInfo1 = "AddlInfo1",
                    AdditionalInfo2 = "AddlInfo2",
                    AlertCondition = "Condition",
                    ReferenceId = "RefID123"
                };

            logWriter.WriteLog(r);

            NLogLogWriter logWriter2 = new NLogLogWriter(configManager.Object, "UnitTest2");

            r.ReferenceId = "RefID345";

            logWriter.WriteLog(r);

            logWriter.Flush();
        }
Ejemplo n.º 9
0
        public void WriteLogWithPrimaryTargetFailure()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug", false);

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);
            logWriter.WriteLog(LogSeverityType.Error, "WriteLogWithPrimaryTargetFailure", "Message text");
            logWriter.Flush();

            logWriter.WriteLog(LogSeverityType.Error, "WriteLogWithPrimaryTargetFailure", "Message text 2nd try");
            logWriter.Flush();
        }
Ejemplo n.º 10
0
        public void WriteLogWithMultipleThreads()
        {
            int count = 5;

            List<Thread> threads = new List<Thread>();

            for (int x = 0; x <= count; x++)
            {
                threads.Add(new Thread(WriteThread));
            }

            for (int x = 0; x < count; x++)
            {
                threads[x].Start();
            }

            for (int x = 0; x < count; x++)
            {
                Assert.IsTrue(threads[x].Join(1000000), "Thread timed out");
            }

            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object, "WriteThread");

            logWriter.Flush();
        }
Ejemplo n.º 11
0
        public void WriteLogWithMessage()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);
            logWriter.WriteLog(LogSeverityType.Info , "WriteLogWithMessage", "Message text");

            logWriter.Flush();
        }