コード例 #1
0
        public void TestingExceptionProcessor_ShouldPass()
        {
            var logger = new Mock <ILogger>();
            var basicWebAppException = new BasicWebAppException();

            ExceptionProcessor.Process(LoggingEvents.ReadItemsFailed, logger.Object, basicWebAppException);

            Assert.True(true, "Testing completed without exceptions. This behaviour should be.");
        }
コード例 #2
0
        public void TestingBasicWebAppExceptionModel_GettingSettingProperties_ShouldPass()
        {
            var basicWebAppException = new BasicWebAppException();

            Assert.Equal("Basic exception", basicWebAppException.Message);

            basicWebAppException = new BasicWebAppException("New exception message");
            Assert.Equal("New exception message", basicWebAppException.Message);

            basicWebAppException = new BasicWebAppException(new ArgumentException());
            Assert.IsType <ArgumentException>(basicWebAppException.InnerException);

            basicWebAppException = new BasicWebAppException("Again new exception message", new IndexOutOfRangeException());
            Assert.Equal("Again new exception message", basicWebAppException.Message);
            Assert.IsType <IndexOutOfRangeException>(basicWebAppException.InnerException);
        }
コード例 #3
0
        public static void Process(EventId eventId, ILogger logger, BasicWebAppException exception, params object[] parameters)
        {
            // Logging.
            var messageTemplate = "{Message}";

            if (parameters?.Length > 0)
            {
                messageTemplate = "{Message}. Parameters(";

                for (var i = 0; i < parameters.Length - 1; i++)
                {
                    messageTemplate += $"p{i + 1}={{p{i + 1}}}, ";
                }

                messageTemplate += $"p{parameters.Length}={{p{parameters.Length}}})";
            }

            logger.LogError(eventId, exception, messageTemplate, exception.Message, parameters);
        }