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();
        }
        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);
            }
        }
        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();
        }
        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();
        }
        public void WriteLogWithMessage()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

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

            logWriter.Flush();
        }