Exemplo n.º 1
0
        TimeSpan GetTimeToRestartErrorIngestionAfterFailure()
        {
            string message;
            var    valueRead = SettingsReader <string> .Read("TimeToRestartErrorIngestionAfterFailure");

            if (valueRead == null)
            {
                return(TimeSpan.FromSeconds(60));
            }

            if (TimeSpan.TryParse(valueRead, out var result))
            {
                if (ValidateConfiguration && result < TimeSpan.FromSeconds(5))
                {
                    message = "TimeToRestartErrorIngestionAfterFailure setting is invalid, value should be minimum 5 seconds.";
                    InternalLogger.Fatal(message);
                    throw new Exception(message);
                }

                if (ValidateConfiguration && result > TimeSpan.FromHours(1))
                {
                    message = "TimeToRestartErrorIngestionAfterFailure setting is invalid, value should be maximum 1 hour.";
                    InternalLogger.Fatal(message);
                    throw new Exception(message);
                }
            }
            else
            {
                message = "TimeToRestartErrorIngestionAfterFailure setting is invalid, please make sure it is a TimeSpan.";
                InternalLogger.Fatal(message);
                throw new Exception(message);
            }

            return(result);
        }
Exemplo n.º 2
0
        public void TimestampTests()
        {
            InternalLogger.LogLevel         = LogLevel.Trace;
            InternalLogger.IncludeTimestamp = true;
            InternalLogger.LogToConsole     = true;

            StringWriter consoleOutWriter = new StringWriter()
            {
                NewLine = "\n"
            };

            // Redirect the console output to a StringWriter.
            Console.SetOut(consoleOutWriter);

            // Named (based on LogLevel) public methods.
            InternalLogger.Warn("WWW");
            InternalLogger.Error("EEE");
            InternalLogger.Fatal("FFF");
            InternalLogger.Trace("TTT");
            InternalLogger.Debug("DDD");
            InternalLogger.Info("III");

            string expectedDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

            var strings = consoleOutWriter.ToString().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var str in strings)
            {
                Assert.Contains(expectedDateTime + ".", str);
            }
        }
Exemplo n.º 3
0
        private void RequestCallback(IAsyncResult result)
        {
            InternalLogger.Trace("{0}.RequestCallback({1})", GetType(), result);

            // Get it back
            var request = result.AsyncState as HttpWebRequest;

            if (request == null)
            {
                InternalLogger.Fatal("{0}.AsyncState was null or not of type {1}.", typeof(IAsyncResult), typeof(HttpWebRequest));
                return;
            }

            WebResponse response;

            // We want to swallow any error responses
            try
            {
                response = request.EndGetResponse(result);
            }
            catch (WebException exception)
            {
                // Since an exception was already thrown, allowing another one to bubble up is pointless
                InternalLogger.Fatal("An error occurred while retriving the Airbrake web response: {0}, web response: {1}",
                                     exception.Message, exception.Response);

                response = exception.Response;
            }

            OnRequestEnd(request, response);
        }
Exemplo n.º 4
0
        public void TimestampTests()
        {
            using (new InternalLoggerScope())
            {
                InternalLogger.LogLevel         = LogLevel.Trace;
                InternalLogger.IncludeTimestamp = true;
                StringWriter consoleOutWriter = new StringWriter()
                {
                    NewLine = ";"
                };

                InternalLogger.LogWriter = consoleOutWriter;

                // Set fixed time source to test time output
                TimeSource.Current = new FixedTimeSource(DateTime.Now);

                // Named (based on LogLevel) public methods.
                InternalLogger.Warn("WWW");
                InternalLogger.Error("EEE");
                InternalLogger.Fatal("FFF");
                InternalLogger.Trace("TTT");
                InternalLogger.Debug("DDD");
                InternalLogger.Info("III");

                string expectedDateTime = TimeSource.Current.Time.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

                var strings = consoleOutWriter.ToString().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var str in strings)
                {
                    Assert.Contains(expectedDateTime + ".", str);
                }
            }
        }
Exemplo n.º 5
0
        private void OnRequestEnd(WebRequest request, WebResponse response)
        {
            if (response == null)
            {
                InternalLogger.Fatal("No response received!");
                return;
            }

            string responseBody;

            using (var responseStream = response.GetResponseStream())
            {
                if (responseStream == null)
                {
                    return;
                }

                using (var sr = new StreamReader(responseStream))
                {
                    responseBody = sr.ReadToEnd();
                    InternalLogger.Debug("Received from Airbrake.\n{0}", responseBody);
                }
            }

            if (RequestEnd != null)
            {
                RequestEndEventArgs e = new RequestEndEventArgs(request, response, responseBody);
                RequestEnd(this, e);
            }
        }
Exemplo n.º 6
0
        protected override void Write(LogEventInfo logEvent)
        {
            var logMessage = Layout.Render(logEvent);
            var subject    = Subject.Render(logEvent);

            var count = Encoding.UTF8.GetByteCount(logMessage);

            if (count > ConfiguredMaxMessageSizeInBytes)
            {
                if (InternalLogger.IsWarnEnabled)
                {
                    InternalLogger.Warn("logging message will be truncted. original message is\n{0}",
                                        logMessage);
                }
                logMessage = logMessage.LeftB(TransferEncoding, truncateSizeInBytes)
                             + TruncateMessage;
            }
            try
            {
                client.Publish(new PublishRequest()
                {
                    Message  = logMessage,
                    Subject  = subject,
                    TopicArn = TopicArn
                });
            }
            catch (AmazonSimpleNotificationServiceException e)
            {
                InternalLogger.Fatal("RequstId: {0},ErrorType: {1}, Status: {2}\nFailed to send log with\n{3}\n{4}",
                                     e.RequestId, e.ErrorType, e.StatusCode,
                                     e.Message, e.StackTrace);
            }
        }
Exemplo n.º 7
0
        public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args)
        {
            switch (logLevel)
            {
            case SentryLevel.Fatal:
                InternalLogger.Fatal(exception, message, args);
                break;

            case SentryLevel.Error:
                InternalLogger.Error(exception, message, args);
                break;

            case SentryLevel.Warning:
                InternalLogger.Warn(exception, message, args);
                break;

            case SentryLevel.Info:
                InternalLogger.Info(exception, message, args);
                break;

            default:
                InternalLogger.Debug(exception, message, args);
                break;
            }

            if (_extraLogger?.IsEnabled(logLevel) == true)
            {
                _extraLogger.Log(logLevel, message, exception, args);
            }
        }
Exemplo n.º 8
0
        TimeSpan?GetAuditRetentionPeriod()
        {
            string message;
            var    valueRead = SettingsReader <string> .Read("AuditRetentionPeriod");

            if (valueRead == null)
            {
                return(null);
            }

            if (TimeSpan.TryParse(valueRead, out var result))
            {
                if (ValidateConfiguration && result < TimeSpan.FromHours(1))
                {
                    message = "AuditRetentionPeriod settings is invalid, value should be minimum 1 hour.";
                    InternalLogger.Fatal(message);
                    throw new Exception(message);
                }

                if (ValidateConfiguration && result > TimeSpan.FromDays(365))
                {
                    message = "AuditRetentionPeriod settings is invalid, value should be maximum 365 days.";
                    InternalLogger.Fatal(message);
                    throw new Exception(message);
                }
            }
            else
            {
                message = "AuditRetentionPeriod settings is invalid, please make sure it is a TimeSpan.";
                InternalLogger.Fatal(message);
                throw new Exception(message);
            }

            return(result);
        }
        public void ShouldLogToTraceWhenInternalLogToTraceIsOnAndLogLevelIsFatal(bool?internalLogToTrace, bool?logToTrace)
        {
            var mockTraceListener = SetupTestConfiguration <MockTraceListener>(LogLevel.Fatal, internalLogToTrace, logToTrace);

            InternalLogger.Fatal("Logger1 Hello");

            Assert.Equal(1, mockTraceListener.Messages.Count);
            Assert.Equal("NLog: Fatal Logger1 Hello" + Environment.NewLine, mockTraceListener.Messages.First());
        }
Exemplo n.º 10
0
        public void WriteToConsoleErrorTests()
        {
            using (var loggerScope = new InternalLoggerScope(true))
            {
                // Expected result is the same for both types of method invocation.
                const string expected = "Warn WWW\nError EEE\nFatal FFF\nTrace TTT\nDebug DDD\nInfo III\n";

                InternalLogger.LogLevel          = LogLevel.Trace;
                InternalLogger.IncludeTimestamp  = false;
                InternalLogger.LogToConsoleError = true;

                {
                    StringWriter consoleWriter1 = new StringWriter()
                    {
                        NewLine = "\n"
                    };

                    // Redirect the console output to a StringWriter.
                    loggerScope.SetConsoleError(consoleWriter1);

                    // Named (based on LogLevel) public methods.
                    InternalLogger.Warn("WWW");
                    InternalLogger.Error("EEE");
                    InternalLogger.Fatal("FFF");
                    InternalLogger.Trace("TTT");
                    InternalLogger.Debug("DDD");
                    InternalLogger.Info("III");

                    TestWriter(expected, loggerScope.ConsoleErrorWriter);
                }

                {
                    //
                    // Redirect the console output to another StringWriter.

                    StringWriter consoleWriter2 = new StringWriter()
                    {
                        NewLine = "\n"
                    };
                    loggerScope.SetConsoleError(consoleWriter2);

                    // Invoke Log(LogLevel, string) for every log level.
                    InternalLogger.Log(LogLevel.Warn, "WWW");
                    InternalLogger.Log(LogLevel.Error, "EEE");
                    InternalLogger.Log(LogLevel.Fatal, "FFF");
                    InternalLogger.Log(LogLevel.Trace, "TTT");
                    InternalLogger.Log(LogLevel.Debug, "DDD");
                    InternalLogger.Log(LogLevel.Info, "III");
                    TestWriter(expected, loggerScope.ConsoleErrorWriter);
                }
            }
        }
Exemplo n.º 11
0
        public static IFileWrapper CreateForPath([NotNull] string filePath)
        {
            try
            {
                return(new FileWrapper(filePath));
            }
            catch (Exception ex)
            {
                InternalLogger.Fatal(ex, "Unable to use file {0}", filePath);
            }

            return(NullFileWrapper.Instance);
        }
Exemplo n.º 12
0
        public void WriteToStringWriterWithArgsTests()
        {
            try
            {
                // Expected result is the same for both types of method invocation.
                const string expected = "Warn WWW 0\nError EEE 0, 1\nFatal FFF 0, 1, 2\nTrace TTT 0, 1, 2\nDebug DDD 0, 1\nInfo III 0\n";

                InternalLogger.LogLevel         = LogLevel.Trace;
                InternalLogger.IncludeTimestamp = false;
                {
                    StringWriter writer1 = new StringWriter()
                    {
                        NewLine = "\n"
                    };
                    InternalLogger.LogWriter = writer1;

                    // Named (based on LogLevel) public methods.
                    InternalLogger.Warn("WWW {0}", 0);
                    InternalLogger.Error("EEE {0}, {1}", 0, 1);
                    InternalLogger.Fatal("FFF {0}, {1}, {2}", 0, 1, 2);
                    InternalLogger.Trace("TTT {0}, {1}, {2}", 0, 1, 2);
                    InternalLogger.Debug("DDD {0}, {1}", 0, 1);
                    InternalLogger.Info("III {0}", 0);

                    TestWriter(expected, writer1);
                }
                {
                    //
                    // Reconfigure the LogWriter.

                    StringWriter writer2 = new StringWriter()
                    {
                        NewLine = "\n"
                    };
                    InternalLogger.LogWriter = writer2;

                    // Invoke Log(LogLevel, string) for every log level.
                    InternalLogger.Log(LogLevel.Warn, "WWW {0}", 0);
                    InternalLogger.Log(LogLevel.Error, "EEE {0}, {1}", 0, 1);
                    InternalLogger.Log(LogLevel.Fatal, "FFF {0}, {1}, {2}", 0, 1, 2);
                    InternalLogger.Log(LogLevel.Trace, "TTT {0}, {1}, {2}", 0, 1, 2);
                    InternalLogger.Log(LogLevel.Debug, "DDD {0}, {1}", 0, 1);
                    InternalLogger.Log(LogLevel.Info, "III {0}", 0);
                    TestWriter(expected, writer2);
                }
            }
            finally
            {
                InternalLogger.Reset();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sends the specified notice to Airbrake.
        /// </summary>
        /// <param name="notice">The notice.</param>
        public void Send(AirbrakeNotice notice)
        {
            InternalLogger.Debug("{0}.Send({1})", GetType(), notice);

            try
            {
                // If no API key, get it from the appSettings
                if (String.IsNullOrEmpty(notice.ApiKey))
                {
                    // If none is set, just return... throwing an exception is pointless, since one was already thrown!
                    if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["Airbrake.ApiKey"]))
                    {
                        InternalLogger.Fatal("No 'Airbrake.ApiKey' found. Please define one in AppSettings.");
                        return;
                    }

                    notice.ApiKey = this.builder.Configuration.ApiKey;
                }

                // Create the web request
                var request = WebRequest.Create(this.configuration.ServerUri) as HttpWebRequest;

                if (request == null)
                {
                    InternalLogger.Fatal("Couldn't create a request to '{0}'.", this.configuration.ServerUri);
                    return;
                }

                // Set the basic headers
                request.ContentType = "text/xml";
                request.Accept      = "text/xml";
                request.KeepAlive   = false;

                // It is important to set the method late... .NET quirk, it will interfere with headers set after
                request.Method = "POST";

                InternalLogger.Debug("Sending Airbrake notice to {0} with key {1}, env: {2}",
                                     this.configuration.ServerUri, this.configuration.ApiKey, this.configuration.EnvironmentName);

                // Go populate the body
                SetRequestBody(request, notice);

                // Begin the request, yay async
                request.BeginGetResponse(RequestCallback, request);
            }
            catch (Exception ex)
            {
                InternalLogger.Fatal("An error occurred while trying to send to Airbrake: {0}", ex.Message);
            }
        }
Exemplo n.º 14
0
        public void TestMinLevelSwitch_lambda(string rawLogLevel, int count)
        {
            Action log = () =>
            {
                InternalLogger.Fatal(() => "L1");
                InternalLogger.Error(() => "L2");
                InternalLogger.Warn(() => "L3");
                InternalLogger.Info(() => "L4");
                InternalLogger.Debug(() => "L5");
                InternalLogger.Trace(() => "L6");
            };

            TestMinLevelSwitch_inner(rawLogLevel, count, log);
        }
Exemplo n.º 15
0
        public void ExceptionTests()
        {
            using (new InternalLoggerScope())
            {
                InternalLogger.LogLevel         = LogLevel.Trace;
                InternalLogger.LogToConsole     = true;
                InternalLogger.IncludeTimestamp = false;

                var ex1 = new Exception("e1");
                var ex2 = new Exception("e2", new Exception("inner"));
                var ex3 = new NLogConfigurationException("config error");
                var ex4 = new NLogConfigurationException("config error", ex2);
                var ex5 = new PathTooLongException();
                ex5.Data["key1"] = "value1";
                Exception ex6 = null;

                const string prefix   = " Exception: ";
                string       expected =
                    "Warn WWW" + prefix + ex1 + Environment.NewLine +
                    "Error EEE" + prefix + ex2 + Environment.NewLine +
                    "Fatal FFF" + prefix + ex3 + Environment.NewLine +
                    "Trace TTT" + prefix + ex4 + Environment.NewLine +
                    "Debug DDD" + prefix + ex5 + Environment.NewLine +
                    "Info III" + Environment.NewLine;

                StringWriter consoleOutWriter = new StringWriter()
                {
                    NewLine = Environment.NewLine
                };

                // Redirect the console output to a StringWriter.
                Console.SetOut(consoleOutWriter);

                // Named (based on LogLevel) public methods.

                InternalLogger.Warn(ex1, "WWW");
                InternalLogger.Error(ex2, "EEE");
                InternalLogger.Fatal(ex3, "FFF");
                InternalLogger.Trace(ex4, "TTT");
                InternalLogger.Debug(ex5, "DDD");
                InternalLogger.Info(ex6, "III");

                consoleOutWriter.Flush();
                var strings = consoleOutWriter.ToString();
                Assert.Equal(expected, strings);
            }
        }
Exemplo n.º 16
0
        public void WriteToStringWriterTests()
        {
            // Expected result is the same for both types of method invocation.
            const string expected = "Warn WWW\nError EEE\nFatal FFF\nTrace TTT\nDebug DDD\nInfo III\n";

            InternalLogger.LogLevel         = LogLevel.Trace;
            InternalLogger.IncludeTimestamp = false;

            StringWriter writer1 = new StringWriter()
            {
                NewLine = "\n"
            };

            InternalLogger.LogWriter = writer1;

            // Named (based on LogLevel) public methods.
            InternalLogger.Warn("WWW");
            InternalLogger.Error("EEE");
            InternalLogger.Fatal("FFF");
            InternalLogger.Trace("TTT");
            InternalLogger.Debug("DDD");
            InternalLogger.Info("III");

            Assert.True(writer1.ToString() == expected);

            //
            // Reconfigure the LogWriter.

            StringWriter writer2 = new StringWriter()
            {
                NewLine = "\n"
            };

            InternalLogger.LogWriter = writer2;

            // Invoke Log(LogLevel, string) for every log level.
            InternalLogger.Log(LogLevel.Warn, "WWW");
            InternalLogger.Log(LogLevel.Error, "EEE");
            InternalLogger.Log(LogLevel.Fatal, "FFF");
            InternalLogger.Log(LogLevel.Trace, "TTT");
            InternalLogger.Log(LogLevel.Debug, "DDD");
            InternalLogger.Log(LogLevel.Info, "III");

            Assert.True(writer2.ToString() == expected);
        }
Exemplo n.º 17
0
        protected override void InitializeTarget()
        {
            base.InitializeTarget();
            var size = MaxMessageSize ?? DefaultMaxMessageSize;

            if (size <= 0 || size >= 256)
            {
                ConfiguredMaxMessageSizeInBytes = 256 * 1024;
            }
            else if (size <= DefaultMaxMessageSize)
            {
                ConfiguredMaxMessageSizeInBytes = DefaultMaxMessageSize * 1024;
            }
            else
            {
                ConfiguredMaxMessageSizeInBytes = size * 1024;
            }
            InternalLogger.Info(string.Format("Max message size is set to {0} KB.", ConfiguredMaxMessageSizeInBytes / 1024));
            truncateSizeInBytes = ConfiguredMaxMessageSizeInBytes - TransferEncoding.GetByteCount(TruncateMessage);

            try
            {
                if (string.IsNullOrEmpty(AwsAccessKey) && string.IsNullOrEmpty(AwsSecretKey))
                {
                    InternalLogger.Info("AWS Access Keys are not specified. Use Application Setting or EC2 Instance profile for keys.");
                    client = new AmazonSimpleNotificationServiceClient(RegionEndpoint.GetBySystemName(Endpoint));
                }
                else
                {
                    client = new AmazonSimpleNotificationServiceClient(AwsAccessKey, AwsSecretKey, RegionEndpoint.GetBySystemName(Endpoint));
                }
            }
            catch (Exception e)
            {
                InternalLogger.Fatal("Amazon SNS client failed to be configured. This logger wont'be send any message. Error is\n{0}\n{1}", e.Message, e.StackTrace);
            }
        }
Exemplo n.º 18
0
        public void VerifyInternalLoggerLevelFilter(bool? internalLogToTrace, bool? logToTrace)
        {
            foreach (LogLevel logLevelConfig in LogLevel.AllLevels)
            {
                var mockTraceListener = SetupTestConfiguration<MockTraceListener>(logLevelConfig, internalLogToTrace, logToTrace);

                List<string> expected = new List<string>();

                string input = "Logger1 Hello";
                expected.Add(input);
                InternalLogger.Trace(input);
                InternalLogger.Debug(input);
                InternalLogger.Info(input);
                InternalLogger.Warn(input);
                InternalLogger.Error(input);
                InternalLogger.Fatal(input);
                input += "No.{0}";
                expected.Add(string.Format(input, 1));
                InternalLogger.Trace(input, 1);
                InternalLogger.Debug(input, 1);
                InternalLogger.Info(input, 1);
                InternalLogger.Warn(input, 1);
                InternalLogger.Error(input, 1);
                InternalLogger.Fatal(input, 1);
                input += ", We come in {1}";
                expected.Add(string.Format(input, 1, "Peace"));
                InternalLogger.Trace(input, 1, "Peace");
                InternalLogger.Debug(input, 1, "Peace");
                InternalLogger.Info(input, 1, "Peace");
                InternalLogger.Warn(input, 1, "Peace");
                InternalLogger.Error(input, 1, "Peace");
                InternalLogger.Fatal(input, 1, "Peace");
                input += " and we are {2} to god";
                expected.Add(string.Format(input, 1, "Peace", true));
                InternalLogger.Trace(input, 1, "Peace", true);
                InternalLogger.Debug(input, 1, "Peace", true);
                InternalLogger.Info(input, 1, "Peace", true);
                InternalLogger.Warn(input, 1, "Peace", true);
                InternalLogger.Error(input, 1, "Peace", true);
                InternalLogger.Fatal(input, 1, "Peace", true);
                input += ", Please don't {3}";
                expected.Add(string.Format(input, 1, "Peace", true, null));
                InternalLogger.Trace(input, 1, "Peace", true, null);
                InternalLogger.Debug(input, 1, "Peace", true, null);
                InternalLogger.Info(input, 1, "Peace", true, null);
                InternalLogger.Warn(input, 1, "Peace", true, null);
                InternalLogger.Error(input, 1, "Peace", true, null);
                InternalLogger.Fatal(input, 1, "Peace", true, null);
                input += " the {4}";
                expected.Add(string.Format(input, 1, "Peace", true, null, "Messenger"));
                InternalLogger.Trace(input, 1, "Peace", true, null, "Messenger");
                InternalLogger.Debug(input, 1, "Peace", true, null, "Messenger");
                InternalLogger.Info(input, 1, "Peace", true, null, "Messenger");
                InternalLogger.Warn(input, 1, "Peace", true, null, "Messenger");
                InternalLogger.Error(input, 1, "Peace", true, null, "Messenger");
                InternalLogger.Fatal(input, 1, "Peace", true, null, "Messenger");
                Assert.Equal(expected.Count * (LogLevel.Fatal.Ordinal - logLevelConfig.Ordinal + 1), mockTraceListener.Messages.Count);
                for (int i = 0; i < expected.Count; ++i)
                {
                    int msgCount = LogLevel.Fatal.Ordinal - logLevelConfig.Ordinal + 1;
                    for (int j = 0; j < msgCount; ++j)
                    {
                        Assert.True(mockTraceListener.Messages.First().Contains(expected[i]));
                        mockTraceListener.Messages.RemoveAt(0);
                    }
                }
                Assert.Equal(0, mockTraceListener.Messages.Count);
            }
        }
Exemplo n.º 19
0
        public void ExceptionTests()
        {
            using (new InternalLoggerScope())
            {
                InternalLogger.LogLevel         = LogLevel.Trace;
                InternalLogger.IncludeTimestamp = false;

                var ex1 = new Exception("e1");
                var ex2 = new Exception("e2", new Exception("inner"));
                var ex3 = new NLogConfigurationException("config error");
                var ex4 = new NLogConfigurationException("config error", ex2);
                var ex5 = new PathTooLongException();
                ex5.Data["key1"] = "value1";
                Exception ex6 = null;

                const string prefix = " Exception: ";

                {
                    string expected =
                        "Warn WWW1" + prefix + ex1 + Environment.NewLine +
                        "Error EEE1" + prefix + ex2 + Environment.NewLine +
                        "Fatal FFF1" + prefix + ex3 + Environment.NewLine +
                        "Trace TTT1" + prefix + ex4 + Environment.NewLine +
                        "Debug DDD1" + prefix + ex5 + Environment.NewLine +
                        "Info III1" + Environment.NewLine;

                    StringWriter consoleOutWriter = new StringWriter()
                    {
                        NewLine = Environment.NewLine
                    };

                    // Redirect the console output to a StringWriter.
                    InternalLogger.LogWriter = consoleOutWriter;

                    // Named (based on LogLevel) public methods.

                    InternalLogger.Warn(ex1, "WWW1");
                    InternalLogger.Error(ex2, "EEE1");
                    InternalLogger.Fatal(ex3, "FFF1");
                    InternalLogger.Trace(ex4, "TTT1");
                    InternalLogger.Debug(ex5, "DDD1");
                    InternalLogger.Info(ex6, "III1");

                    consoleOutWriter.Flush();
                    var strings = consoleOutWriter.ToString();

                    Assert.Equal(expected, strings);
                }
                {
                    string expected =
                        "Warn WWW2" + prefix + ex1 + Environment.NewLine +
                        "Error EEE2" + prefix + ex2 + Environment.NewLine +
                        "Fatal FFF2" + prefix + ex3 + Environment.NewLine +
                        "Trace TTT2" + prefix + ex4 + Environment.NewLine +
                        "Debug DDD2" + prefix + ex5 + Environment.NewLine +
                        "Info III2" + Environment.NewLine;

                    StringWriter consoleOutWriter = new StringWriter()
                    {
                        NewLine = Environment.NewLine
                    };

                    // Redirect the console output to a StringWriter.
                    InternalLogger.LogWriter = consoleOutWriter;

                    // Named (based on LogLevel) public methods.

                    InternalLogger.Warn(ex1, () => "WWW2");
                    InternalLogger.Error(ex2, () => "EEE2");
                    InternalLogger.Fatal(ex3, () => "FFF2");
                    InternalLogger.Trace(ex4, () => "TTT2");
                    InternalLogger.Debug(ex5, () => "DDD2");
                    InternalLogger.Info(ex6, () => "III2");

                    consoleOutWriter.Flush();
                    var strings = consoleOutWriter.ToString();
                    Assert.Equal(expected, strings);
                }
                {
                    string expected =
                        "Warn WWW3" + prefix + ex1 + Environment.NewLine +
                        "Error EEE3" + prefix + ex2 + Environment.NewLine +
                        "Fatal FFF3" + prefix + ex3 + Environment.NewLine +
                        "Trace TTT3" + prefix + ex4 + Environment.NewLine +
                        "Debug DDD3" + prefix + ex5 + Environment.NewLine +
                        "Info III3" + Environment.NewLine;

                    StringWriter consoleOutWriter = new StringWriter()
                    {
                        NewLine = Environment.NewLine
                    };

                    // Redirect the console output to a StringWriter.
                    InternalLogger.LogWriter = consoleOutWriter;

                    // Named (based on LogLevel) public methods.

                    InternalLogger.Log(ex1, LogLevel.Warn, "WWW3");
                    InternalLogger.Log(ex2, LogLevel.Error, "EEE3");
                    InternalLogger.Log(ex3, LogLevel.Fatal, "FFF3");
                    InternalLogger.Log(ex4, LogLevel.Trace, "TTT3");
                    InternalLogger.Log(ex5, LogLevel.Debug, "DDD3");
                    InternalLogger.Log(ex6, LogLevel.Info, "III3");

                    consoleOutWriter.Flush();
                    var strings = consoleOutWriter.ToString();
                    Assert.Equal(expected, strings);
                }
                {
                    string expected =
                        "Warn WWW4" + prefix + ex1 + Environment.NewLine +
                        "Error EEE4" + prefix + ex2 + Environment.NewLine +
                        "Fatal FFF4" + prefix + ex3 + Environment.NewLine +
                        "Trace TTT4" + prefix + ex4 + Environment.NewLine +
                        "Debug DDD4" + prefix + ex5 + Environment.NewLine +
                        "Info III4" + Environment.NewLine;

                    StringWriter consoleOutWriter = new StringWriter()
                    {
                        NewLine = Environment.NewLine
                    };

                    // Redirect the console output to a StringWriter.
                    InternalLogger.LogWriter = consoleOutWriter;

                    // Named (based on LogLevel) public methods.

                    InternalLogger.Log(ex1, LogLevel.Warn, () => "WWW4");
                    InternalLogger.Log(ex2, LogLevel.Error, () => "EEE4");
                    InternalLogger.Log(ex3, LogLevel.Fatal, () => "FFF4");
                    InternalLogger.Log(ex4, LogLevel.Trace, () => "TTT4");
                    InternalLogger.Log(ex5, LogLevel.Debug, () => "DDD4");
                    InternalLogger.Log(ex6, LogLevel.Info, () => "III4");

                    var strings = consoleOutWriter.ToString();
                    Assert.Equal(expected, strings);
                }
            }
        }