Exemplo n.º 1
0
        public void CsvNonAgnostic()
        {
            CsvLayout l = new CsvLayout()
            {
                Columns =
                {
                    new CsvColumn("name1", "${message}"),
                    new CsvColumn("name2", "${threadname}"),
                    new CsvColumn("name3", "${longdate}"),
                },
            };

            l.Initialize(null);
            Assert.False(l.ThreadAgnostic);
        }
Exemplo n.º 2
0
        public void CsvThreadAgnostic()
        {
            CsvLayout l = new CsvLayout()
            {
                Columns =
                {
                    new CsvColumn("name1", "${message}"),
                    new CsvColumn("name2", "${level}"),
                    new CsvColumn("name3", "${longdate}"),
                },
            };

            l.Initialize(null);
            Assert.True(l.IsThreadAgnostic);
        }
Exemplo n.º 3
0
        public void CsvLayoutTest()
        {
            var layout = new CsvLayout()
            {
                Delimiter  = CsvColumnDelimiterMode.Semicolon,
                WithHeader = true,
                Columns    =
                {
                    new CsvColumn("name",    "${logger}"),
                    new CsvColumn("level",   "${level}"),
                    new CsvColumn("message", "${message}"),
                }
            };

            var mmt = new MockMailTarget
            {
                From        = "*****@*****.**",
                To          = "*****@*****.**",
                SmtpServer  = "server1",
                AddNewLines = true,
                Layout      = layout,
            };

            layout.Initialize(null);

            mmt.Initialize(null);

            var exceptions = new List <Exception>();

            mmt.WriteAsyncLogEvents(
                new LogEventInfo(LogLevel.Info, "MyLogger1", "log message 1").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Debug, "MyLogger2", "log message 2").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Error, "MyLogger3", "log message 3").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            Assert.Single(mmt.CreatedMocks);

            var mock = mmt.CreatedMocks[0];

            Assert.Single(mock.MessagesSent);
            var    msg          = mock.MessagesSent[0];
            string expectedBody = "name;level;message\nMyLogger1;Info;log message 1\nMyLogger2;Debug;log message 2\nMyLogger3;Error;log message 3\n";

            Assert.Equal(expectedBody, msg.Body);
        }