Exemplo n.º 1
0
 public void LayoutRendererThrows()
 {
     ConfigurationItemFactory configurationItemFactory = new ConfigurationItemFactory();
     configurationItemFactory.LayoutRenderers.RegisterDefinition("throwsException", typeof(ThrowsExceptionRenderer));
     var cfg = new LoggingConfiguration(configurationItemFactory);
     SimpleLayout l = new SimpleLayout("xx${throwsException}yy", cfg);
     l.Initialize(cfg);
     string output = l.Render(LogEventInfo.CreateNullEvent());
     Assert.AreEqual("xxyy", output);
 }
        /// <summary>
        /// Get the headers with the column names.
        /// </summary>
        /// <returns></returns>
        private void RenderHeader(StringBuilder sb)
        {
            LogEventInfo logEvent = LogEventInfo.CreateNullEvent();

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < Columns.Count; i++)
            {
                CsvColumn col          = Columns[i];
                var       columnLayout = new SimpleLayout(new LayoutRenderers.LayoutRenderer[] { new LayoutRenderers.LiteralLayoutRenderer(col.Name) }, col.Name, ConfigurationItemFactory.Default);
                columnLayout.Initialize(LoggingConfiguration);
                RenderColumnLayout(logEvent, columnLayout, col._quoting ?? Quoting, sb, i);
            }
        }
Exemplo n.º 3
0
 public void WrapperOverAgnostic()
 {
     Layout l = new SimpleLayout("${rot13:${message}}");
     l.Initialize(null);
     Assert.True(l.IsThreadAgnostic);
 }
Exemplo n.º 4
0
 public void AgnosticPlusAgnostic()
 {
     Layout l = new SimpleLayout("${message}${level}${logger}");
     l.Initialize(null);
     Assert.True(l.IsThreadAgnostic);
 }
Exemplo n.º 5
0
 public void AgnosticPlusNonAgnostic()
 {
     Layout l = new SimpleLayout("${message}${threadname}");
     l.Initialize(null);
     Assert.False(l.IsThreadAgnostic);
 }
Exemplo n.º 6
0
 public void NonThreadAgnosticTest()
 {
     Layout l = new SimpleLayout("${threadname}");
     l.Initialize(null);
     Assert.False(l.IsThreadAgnostic);
 }
Exemplo n.º 7
0
 public void ThreadAgnosticTest()
 {
     Layout l = new SimpleLayout("${message}");
     l.Initialize(null);
     Assert.True(l.IsThreadAgnostic);
 }
Exemplo n.º 8
0
        public void CustomAgnosticTests()
        {
            var cif = new ConfigurationItemFactory();
            cif.RegisterType(typeof(CustomRendererAgnostic), string.Empty);

            Layout l = new SimpleLayout("${customAgnostic}", cif);

            l.Initialize(null);
            Assert.True(l.IsThreadAgnostic);
        }
Exemplo n.º 9
0
 public void TripleWrapperOverNonAgnostic()
 {
     Layout l = new SimpleLayout("${uppercase:${lowercase:${rot13:${message}${threadname}}}}");
     l.Initialize(null);
     Assert.False(l.IsThreadAgnostic);
 }
Exemplo n.º 10
0
 public void SimpleLayoutCachingTest()
 {
     var l = new SimpleLayout("xx${level}yy");
     var ev = LogEventInfo.CreateNullEvent();
     l.Initialize(CommonCfg);
     string output1 = l.Render(ev);
     string output2 = l.Render(ev);
     Assert.AreSame(output1, output2);
 }
Exemplo n.º 11
0
        public void LayoutRendererThrows2()
        {
            string internalLogOutput = RunAndCaptureInternalLog(
                () =>
                    {
                        ConfigurationItemFactory configurationItemFactory = new ConfigurationItemFactory();
                        configurationItemFactory.LayoutRenderers.RegisterDefinition("throwsException", typeof(ThrowsExceptionRenderer));

                        SimpleLayout l = new SimpleLayout("xx${throwsException:msg1}yy${throwsException:msg2}zz", new LoggingConfiguration(configurationItemFactory));
                        l.Initialize(CommonCfg);
                        string output = l.Render(LogEventInfo.CreateNullEvent());
                        Assert.AreEqual("xxyyzz", output);
                    },
                    LogLevel.Warn);

            Assert.IsTrue(internalLogOutput.IndexOf("msg1") >= 0, internalLogOutput);
            Assert.IsTrue(internalLogOutput.IndexOf("msg2") >= 0, internalLogOutput);
        }
Exemplo n.º 12
0
 public void TripleWrapperOverAgnostic()
 {
     Layout l = new SimpleLayout("${uppercase:${lowercase:${rot13:${message}}}}");
     l.Initialize(CommonCfg);
     Assert.IsTrue(l.IsThreadAgnostic);
 }
Exemplo n.º 13
0
        public void CustomNotAgnosticTests()
        {
            var cif = new ConfigurationItemFactory();
            cif.RegisterType(typeof(CustomRendererNonAgnostic), string.Empty);
            var cfg = new LoggingConfiguration(cif);
            Layout l = new SimpleLayout("${customNotAgnostic}", cfg);

            l.Initialize(cfg);
            Assert.IsFalse(l.IsThreadAgnostic);
        }