Ejemplo n.º 1
0
        public void ErrorException_should_not_throw_exception_when_exception_message_property_throw_exception_serialize()
        {
            LogManager.Configuration = XmlLoggingConfiguration.CreateFromXmlString(@"
            <nlog>
                <targets>
                    <target name='debug1' type='Debug' layout='${exception:format=@}' />
                </targets>
                <rules>
                    <logger minlevel='Info' writeTo='debug1' />
                </rules>
            </nlog>");

            var ex         = new ExceptionWithBrokenMessagePropertyException();
            var exRecorded = Record.Exception(() => logger.Error(ex, "msg"));

            Assert.Null(exRecorded);
        }
Ejemplo n.º 2
0
        public void ErrorException_should_not_throw_exception_when_exception_message_property_throw_exception()
        {
            LogManager.Configuration = CreateConfigurationFromString(@"
            <nlog>
                <targets>
                    <target name='debug1' type='Debug' layout='${exception}' />
                </targets>
                <rules>
                    <logger minlevel='Info' writeTo='debug1' />
                </rules>
            </nlog>");

            var ex = new ExceptionWithBrokenMessagePropertyException();

            Assert.ThrowsDelegate action = () => _logger.ErrorException("msg", ex);

            Assert.DoesNotThrow(action);
        }
        public void ErrorException_should_not_throw_exception_when_exception_message_property_throw_exception()
        {
            LogManager.Configuration = CreateConfigurationFromString(@"
            <nlog>
                <targets>
                    <target name='debug1' type='Debug' layout='${exception}' />
                </targets>
                <rules>
                    <logger minlevel='Info' writeTo='debug1' />
                </rules>
            </nlog>");

            var ex = new ExceptionWithBrokenMessagePropertyException();

            Assert.ThrowsDelegate action = () => _logger.ErrorException("msg", ex);

            Assert.DoesNotThrow(action);
        }
Ejemplo n.º 4
0
        public void ErrorException_should_not_throw_exception_when_exception_message_property_throw_exception()
        {
            LogManager.Configuration = CreateConfigurationFromString(@"
            <nlog>
                <targets>
                    <target name='debug1' type='Debug' layout='${exception}' />
                </targets>
                <rules>
                    <logger minlevel='Info' writeTo='debug1' />
                </rules>
            </nlog>");

            var ex = new ExceptionWithBrokenMessagePropertyException();

#pragma warning disable 0618
            // Obsolete method requires testing until completely removed.
            Assert.ThrowsDelegate action = () => logger.ErrorException("msg", ex);
#pragma warning restore 0618
            Assert.DoesNotThrow(action);
        }