Example #1
0
        public void logging_multiple_lines()
        {
            TestHelper.LogsToConsole = true;
            var m = new ActivityMonitor(false);

            m.MinimalFilter = LogFilter.Debug;
            StringBuilder b      = new StringBuilder();
            var           client = new ActivityMonitorTextWriterClient(s => b.Append(s));

            m.Output.RegisterClient(client);
            using (TestHelper.ConsoleMonitor.SetMinimalFilter(LogFilter.Debug))
                using (m.Output.CreateBridgeTo(TestHelper.ConsoleMonitor.Output.BridgeTarget))
                {
                    using (m.OpenInfo().Send("IL1" + Environment.NewLine + "IL2" + Environment.NewLine + "IL3"))
                    {
                        using (m.OpenTrace().Send("TL1" + Environment.NewLine + "TL2" + Environment.NewLine + "TL3"))
                        {
                            m.Warn().Send("WL1" + Environment.NewLine + "WL2" + Environment.NewLine + "WL3");
                            m.CloseGroup(new[]
                            {
                                new ActivityLogGroupConclusion("c1"),
                                new ActivityLogGroupConclusion("c2"),
                                new ActivityLogGroupConclusion("Multi" + Environment.NewLine + "Line" + Environment.NewLine),
                                new ActivityLogGroupConclusion("Another" + Environment.NewLine + "Multi" + Environment.NewLine + "Line" + Environment.NewLine)
                            });
                        }
                    }
                }
            string result = b.ToString();

            Assert.That(result, Is.EqualTo(
                            @"> Info: IL1
|       IL2
|       IL3
|  > Trace: TL1
|  |        TL2
|  |        TL3
|  |  - Warn: WL1
|  |          WL2
|  |          WL3
|  < c1 - c2
|  < Multi
|    Line
|  < Another
|    Multi
|    Line
".NormalizeEOL()));
        }
        public void logging_multiple_lines()
        {
            TestHelper.LogsToConsole = true;
            var m = new ActivityMonitor( false );
            m.MinimalFilter = LogFilter.Debug;
            StringBuilder b = new StringBuilder();
            var client = new ActivityMonitorTextWriterClient( s => b.Append( s ) );
            m.Output.RegisterClient( client );
            using( TestHelper.ConsoleMonitor.SetMinimalFilter( LogFilter.Debug ) )
            using( m.Output.CreateBridgeTo( TestHelper.ConsoleMonitor.Output.BridgeTarget ) )
            {
                using( m.OpenInfo().Send( "IL1" + Environment.NewLine + "IL2" + Environment.NewLine + "IL3" ) )
                {
                    using( m.OpenTrace().Send( "TL1" + Environment.NewLine + "TL2" + Environment.NewLine + "TL3" ) )
                    {
                        m.Warn().Send( "WL1" + Environment.NewLine + "WL2" + Environment.NewLine + "WL3" );
                        m.CloseGroup( new[] 
                        {
                            new ActivityLogGroupConclusion("c1"),
                            new ActivityLogGroupConclusion("c2"),
                            new ActivityLogGroupConclusion("Multi"+Environment.NewLine+"Line"+Environment.NewLine),
                            new ActivityLogGroupConclusion("Another"+Environment.NewLine+"Multi"+Environment.NewLine+"Line"+Environment.NewLine)
                        } );
                    }
                }
            }
            string result = b.ToString();
            Assert.That( result, Is.EqualTo(
@"> Info: IL1
|       IL2
|       IL3
|  > Trace: TL1
|  |        TL2
|  |        TL3
|  |  - Warn: WL1
|  |          WL2
|  |          WL3
|  < c1 - c2
|  < Multi
|    Line
|  < Another
|    Multi
|    Line
".NormalizeEOL() ) );
        }
        public void FilteredTextWriterTests()
        {
            StringBuilder sb = new StringBuilder();

            IActivityMonitor d = new ActivityMonitor();
            d.SetMinimalFilter( LogFilter.Debug );

            var c = new ActivityMonitorTextWriterClient(s => sb.Append(s), LogFilter.Release);
            d.Output.RegisterClient( c );

            d.Trace().Send( "NO SHOW" );
            d.Trace().Send( "NO SHOW" );
            using( d.OpenTrace().Send( "NO SHOW" ) )
            {
                d.Info().Send( "NO SHOW" );
                d.Info().Send( "NO SHOW" );
            }

            d.Error().Send( "Error line at root" );
            using( d.OpenInfo().Send( "NO SHOW" ) )
            {
                d.Warn().Send( "NO SHOW" );
                d.Error().Send( "Send error line inside group" );
                using( d.OpenError().Send( "Open error group" ) )
                {
                    d.Error().Send( "Send error line inside sub group" );
                }
            }

            Assert.That( sb.ToString(), Does.Not.Contain( "NO SHOW" ) );
            Assert.That( sb.ToString(), Does.Contain( "Error line at root" ) );
            Assert.That( sb.ToString(), Does.Contain( "Send error line inside group" ) );
            Assert.That( sb.ToString(), Does.Contain( "Open error group" ) );
            Assert.That( sb.ToString(), Does.Contain( "Send error line inside sub group" ) );
        }
        public void DumpAggregatedException()
        {
            IActivityMonitor l = new ActivityMonitor( applyAutoConfigurations: false );
            var wLogLovely = new StringBuilder();
            using( l.Output.CreateBridgeTo( TestHelper.ConsoleMonitor.Output.BridgeTarget ) )
            {

                var logLovely = new ActivityMonitorTextWriterClient( ( s ) => wLogLovely.Append( s ) );
                l.Output.RegisterClient( logLovely );


                l.Error().Send( new Exception( "EXERROR-1" ) );
                using( l.OpenFatal().Send( new Exception( "EXERROR-2" ), "EXERROR-TEXT2" ) )
                {
                    try
                    {
                        throw new AggregateException(
                            new Exception( "EXERROR-Aggreg-1" ),
                            new AggregateException(
                                new Exception( "EXERROR-Aggreg-2-1" ),
                                new Exception( "EXERROR-Aggreg-2-2" )
                            ),
                            new Exception( "EXERROR-Aggreg-3" ) );
                    }
                    catch( Exception ex )
                    {
                        l.Error().Send( ex, "EXERROR-TEXT3" );
                    }
                }
            }
            string text = wLogLovely.ToString();
            Assert.That( text, Does.Contain( "EXERROR-Aggreg-1" ) );
            Assert.That( text, Does.Contain( "EXERROR-Aggreg-2-1" ) );
            Assert.That( text, Does.Contain( "EXERROR-Aggreg-2-2" ) );
            Assert.That( text, Does.Contain( "EXERROR-Aggreg-3" ) );
        }