Ejemplo n.º 1
0
        private static void DuplicateTestWith6Entries( int nbEntries1, int nbEntries2, bool gzip = false )
        {
            var folder = String.Format( "{0}\\ReadDuplicates", TestHelper.TestFolder );
            TestHelper.CleanupFolder( folder );
            string config = String.Format( @"
<GrandOutputConfiguration>
    <Channel>
        <Add Type=""BinaryFile"" Name=""All-1"" MaxCountPerFile=""{1}"" Path=""{0}"" UseGzipCompression=""{3}"" /> 
        <Add Type=""BinaryFile"" Name=""All-2"" MaxCountPerFile=""{2}"" Path=""{0}"" UseGzipCompression=""{3}"" /> 
    </Channel>
</GrandOutputConfiguration>
", folder, nbEntries1, nbEntries2, gzip );

            using( var o = new GrandOutput() )
            {
                GrandOutputConfiguration c = new GrandOutputConfiguration();
                Assert.That( c.Load( XDocument.Parse( config ).Root, TestHelper.ConsoleMonitor ), Is.True );
                Assert.That( o.SetConfiguration( c, TestHelper.ConsoleMonitor ), Is.True );

                var m = new ActivityMonitor();
                o.Register( m );
                var direct = m.Output.RegisterClient( new CKMonWriterClient( folder, Math.Min( nbEntries1, nbEntries2 ), LogFilter.Debug, gzip ) );
                // 6 traces that go to the GrandOutput but also to the direct CKMonWriterClient.
                m.Trace().Send( "Trace 1" );
                m.OpenTrace().Send( "OpenTrace 1" );
                m.Trace().Send( "Trace 1.1" );
                m.Trace().Send( "Trace 1.2" );
                m.CloseGroup();
                m.Trace().Send( "Trace 2" );
                System.Threading.Thread.Sleep( 100 );
                m.Output.UnregisterClient( direct );
            }
            var files = TestHelper.WaitForCkmonFilesInDirectory( folder, 3 );
            for( int pageReadLength = 1; pageReadLength < 10; ++pageReadLength )
            {
                MultiLogReader reader = new MultiLogReader();
                reader.Add( files );
                var map = reader.GetActivityMap();
                Assert.That( map.ValidFiles.All( rawFile => rawFile.IsValidFile ), Is.True, "All files are correctly closed with the final 0 byte and no exception occurred while reading them." );

                var readMonitor = map.Monitors.Single();

                List<ParentedLogEntry> allEntries = new List<ParentedLogEntry>();
                using( var pageReader = readMonitor.ReadFirstPage( pageReadLength ) )
                {
                    do
                    {
                        allEntries.AddRange( pageReader.Entries );
                    }
                    while( pageReader.ForwardPage() > 0 );
                }
                CollectionAssert.AreEqual( new[] { "Trace 1", "OpenTrace 1", "Trace 1.1", "Trace 1.2", null, "Trace 2" }, allEntries.Select( e => e.Entry.Text ).ToArray(), StringComparer.Ordinal );
            }
        }
Ejemplo n.º 2
0
        public void ApplyEmptyAndDefaultConfig()
        {
            TestHelper.CleanupFolder( SystemActivityMonitor.RootLogPath + "ApplyEmptyAndDefaultConfig" );

            using( GrandOutput g = new GrandOutput() )
            {
                var m = new ActivityMonitor( false );
                g.Register( m );
                m.Trace().Send( "NoShow-1" );
                Assert.That( g.SetConfiguration( new GrandOutputConfiguration(), TestHelper.ConsoleMonitor ) );
                m.Trace().Send( "NoShow-2" );
                Assert.That( g.SetConfiguration( CreateDefaultConfig( "ApplyEmptyAndDefaultConfig" ), TestHelper.ConsoleMonitor ) );
                m.Trace().Send( "Show-1" );
                Assert.That( g.SetConfiguration( new GrandOutputConfiguration(), TestHelper.ConsoleMonitor ) );
                m.Trace().Send( "NoShow-3" );
            }
            var replayed = new ActivityMonitor( false );
            var c = replayed.Output.RegisterClient( new StupidStringClient() );
            TestHelper.ReplayLogs( new DirectoryInfo( SystemActivityMonitor.RootLogPath + "ApplyEmptyAndDefaultConfig" ), true, mon => replayed, TestHelper.ConsoleMonitor );
            CollectionAssert.AreEqual( new[] { "<Missing log data>", "Show-1" }, c.Entries.Select( e => e.Text ), StringComparer.OrdinalIgnoreCase );
        }
        public void FilteringBySource()
        {
            TestHelper.CleanupFolder( SystemActivityMonitor.RootLogPath + "FilteringBySource" );

            using( GrandOutput g = new GrandOutput() )
            {
                GrandOutputConfiguration config = new GrandOutputConfiguration();
                config.Load( XDocument.Parse( @"
<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""BinaryFile"" Name=""All"" Path=""FilteringBySource"" />
        <Channel Name=""HiddenTopic"" MinimalFilter=""Off"" TopicRegex=""(hidden\s+topic|hide\s+this\s+topic)"" MatchOptions=""CultureInvariant, ExplicitCapture, Compiled, Multiline"" />
    </Channel>
    <SourceOverrideFilter>
        <Add File=""SourceFile-Debug.cs"" Filter=""Debug"" />
        <Add File=""SourceFile-Off.cs"" Filter=""Off"" />
        <Add File=""SourceFile-Strange.cs"" Filter=""{Trace,Fatal}"" />
    </SourceOverrideFilter>
</GrandOutputConfiguration>", LoadOptions.SetLineInfo ).Root, TestHelper.ConsoleMonitor );

                Assert.That( g.SetConfiguration( config, TestHelper.ConsoleMonitor ) );

                var m = new ActivityMonitor( false );
                g.Register( m );

                m.Fatal( fileName: "SourceFile-Off.cs" ).Send( "NOSHOW" );
                m.SetTopic( "This is a hidden topic..." );
                m.Trace( 0, "SourceFile-Debug.cs" ).Send( "Trace-1" );
                m.Trace().Send( "NOSHOW" );
                m.SetTopic( "Please, hide this topic!" );
                m.Trace( fileName: "SourceFile-Strange.cs" ).Send( "NOSHOW" );
                using( m.OpenTrace( fileName: "SourceFile-Strange.cs" ).Send( "Trace-2" ) )
                {
                    m.Trace( fileName: "SourceFile-Strange.cs" ).Send( "NOSHOW" );
                    m.Fatal( fileName: "SourceFile-Strange.cs" ).Send( "Fatal-1" );
                    m.Fatal( fileName: "SourceFile-Off.cs" ).Send( "NOSHOW" );
                }
                m.SetTopic( null );
                m.Trace( fileName: "SourceFile-Strange.cs" ).Send( "NOSHOW" );
                m.Fatal( fileName: "SourceFile-Off.cs" ).Send( "NOSHOW" );
                m.Trace().Send( "Trace-3" );
            }
            List<StupidStringClient> logs = TestHelper.ReadAllLogs( new DirectoryInfo( SystemActivityMonitor.RootLogPath + "FilteringBySource" ), false );
            Assert.That( logs.Count, Is.EqualTo( 1 ) );
            Assert.That( logs[0].ToString(), Does.Not.Contain( "NOSHOW" ) );
            var texts = logs[0].Entries.Select( e => e.Text ).ToArray();
            CollectionAssert.AreEqual( new string[] { 
                "Trace-1", 
                "Trace-2", 
                "Fatal-1", 
                ActivityMonitor.SetTopicPrefix, 
                "Trace-3", 
            }, texts, StringComparer.Ordinal );
        }
Ejemplo n.º 4
0
        static void DumpSampleLogs2( Random r, GrandOutput g )
        {
            var m = new ActivityMonitor( false );
            g.Register( m );

            m.Fatal().Send( ThrowExceptionWithInner( false ), "An error occured" );
            m.SetTopic( "This is a topic..." );
            m.Trace().Send( "a trace" );
            m.Trace().Send( "another one" );
            m.SetTopic( "Please, show this topic!" );
            m.Trace().Send( "Anotther trace." );
            using( m.OpenTrace().Send( "A group trace." ) )
            {
                m.Trace().Send( "A trace in group." );
                m.Info().Send( "An info..." );
                using( m.OpenInfo().Send( @"A group information... with a 
multi
-line
message. 
This MUST be correctly indented!" ) )
                {
                    m.Info().Send( "Info in info group." );
                    m.Info().Send( "Another info in info group." );
                    m.Error().Send( ThrowExceptionWithInner( true ), "An error." );
                    m.Warn().Send( "A warning." );
                    m.Trace().Send( "Something must be said." );
                    m.CloseGroup( "Everything is in place." );
                }
            }
            m.SetTopic( null );
            using( m.OpenTrace().Send( "A group with multiple conclusions." ) )
            {
                using( m.OpenTrace().Send( "A group with no conclusion." ) )
                {
                    m.Trace().Send( "Something must be said." );
                }
                m.CloseGroup( new[] {
                        new ActivityLogGroupConclusion( "My very first conclusion." ),
                        new ActivityLogGroupConclusion( "My second conclusion." ),
                        new ActivityLogGroupConclusion( @"My very last conclusion
is a multi line one.
and this is fine!" )
                    } );
            }
            m.Trace().Send( "This is the final trace." );
        }
Ejemplo n.º 5
0
 static void DumpSampleLogs1( Random r, GrandOutput g )
 {
     var m = new ActivityMonitor( false );
     g.Register( m );
     m.SetTopic( "First Activity..." );
     if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
     using( m.OpenTrace().Send( "Opening trace" ) )
     {
         if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
         m.Trace().Send( "A trace in group." );
         if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
         m.Info().Send( "An info in group." );
         if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
         m.Warn().Send( "A warning in group." );
         if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
         m.Error().Send( "An error in group." );
         if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
         m.Fatal().Send( "A fatal in group." );
     }
     if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) );
     m.Trace().Send( "End of first activity." );
 }
        public void FilteringByTopic()
        {
            TestHelper.CleanupFolder( SystemActivityMonitor.RootLogPath + "FilteringByTopic" );

            using( GrandOutput g = new GrandOutput() )
            {
                GrandOutputConfiguration config = new GrandOutputConfiguration();
                config.Load( XDocument.Parse( @"
<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""BinaryFile"" Name=""All"" Path=""FilteringByTopic"" />
        <Channel Name=""HiddenTopic"" MinimalFilter=""Off"" TopicFilter=""*H*T?pic*"" >
            <Channel Name=""SavedHiddenTopic"" MinimalFilter=""Release"" TopicFilter=""*DOSHOW*"" >
            </Channel>
        </Channel>
        <Channel Name=""MonitoredTopic"" MinimalFilter=""Monitor"" TopicFilter=""*MONITOR*"" >
        </Channel>
    </Channel>
</GrandOutputConfiguration>", LoadOptions.SetLineInfo ).Root, TestHelper.ConsoleMonitor );

                Assert.That( g.SetConfiguration( config, TestHelper.ConsoleMonitor ) );

                var fullyHidden = new ActivityMonitor( false );
                g.Register( fullyHidden );
                fullyHidden.SetTopic( "A fully hidden topic: setting the topic before any send, totally hides the monitor if the Actual filter is Off. - NOSHOW" );
                fullyHidden.Fatal().Send( "NOSHOW" );
                using( fullyHidden.OpenFatal().Send( "NOSHOW" ) )
                {
                    fullyHidden.Fatal().Send( "NOSHOW" );
                }

                var m = new ActivityMonitor( false );
                g.Register( m );
                m.Trace().Send( "Trace-1" );
                m.SetTopic( "This is a Hidden Topic - NOSHOW" );
                m.Fatal().Send( "NOSHOW" );
                m.SetTopic( "Visible Topic" );
                m.Trace().Send( "Trace-2" );
                m.SetTopic( "This is a Hidden Topic but DOSHOW puts it in Release mode." );
                m.Trace().Send( "NOSHOW" );
                m.Info().Send( "NOSHOW" );
                m.Warn().Send( "NOSHOW" );
                m.Error().Send( "Error-1" );
                m.Fatal().Send( "Fatal-1" );
                m.SetTopic( "This is a HT?PIC (off). Match is case insensitive - NOSHOW" );
                m.Fatal().Send( "NOSHOW" );
                m.SetTopic( null );
                m.Trace().Send( "Trace-3" );
                m.SetTopic( "A MONITORed topic: If i wrote This is a t.o.p.i.c (without the dots), this would have matched the HiddenT.o.p.i.c channel..." );
                m.Trace().Send( "NOSHOW" );
                m.Warn().Send( "Warn-1" );
            }
            List<StupidStringClient> logs = TestHelper.ReadAllLogs( new DirectoryInfo( SystemActivityMonitor.RootLogPath + "FilteringByTopic" ), false );
            Assert.That( logs.Count, Is.EqualTo( 1 ), "Fully hidden monitor does not appear." );
            Assert.That( logs[0].ToString(), Does.Not.Contain( "NOSHOW" ) );
            var texts = logs[0].Entries.Select( e => e.Text ).ToArray();
            CollectionAssert.AreEqual( new string[] { 
                "Trace-1", 
                ActivityMonitor.SetTopicPrefix + "Visible Topic", 
                "Trace-2", 
                ActivityMonitor.SetTopicPrefix + "This is a Hidden Topic but DOSHOW puts it in Release mode.", 
                "Error-1", 
                "Fatal-1", 
                ActivityMonitor.SetTopicPrefix, 
                "Trace-3", 
                ActivityMonitor.SetTopicPrefix + "A MONITORed topic: If i wrote This is a t.o.p.i.c (without the dots), this would have matched the HiddenT.o.p.i.c channel...", 
                "Warn-1"
            }, texts, StringComparer.Ordinal );
        }
Ejemplo n.º 7
0
        public void ApplyConfigSimple()
        {
            GrandOutputConfiguration c = new GrandOutputConfiguration();

            Assert.That( c.Load( XDocument.Parse( @"
<GrandOutputConfiguration AppDomainDefaultFilter=""Release"" >
    <Channel MinimalFilter=""{Trace,Info}"">
        <Add Type=""BinaryFile"" Name=""GlobalCatch"" Path=""Configuration/ApplyConfig"" />
    </Channel>
</GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor ) );

            Assert.That( c.ChannelsConfiguration.Configurations.Count, Is.EqualTo( 1 ) );

            ActivityMonitor m = new ActivityMonitor( false );
            using( GrandOutput g = new GrandOutput() )
            {
                m.Info().Send( "Before Registering - NOSHOW" );
                g.Register( m );
                m.Info().Send( "Before configuration - NOSHOW" );
                Assert.That( g.SetConfiguration( c, TestHelper.ConsoleMonitor ) );
                m.Info().Send( "After configuration. INFO1" );

                Assert.That( m.ActualFilter, Is.EqualTo( new LogFilter( LogLevelFilter.Trace, LogLevelFilter.Info ) ) ); 
                m.Trace().Send( "TRACE1-NOSHOW (MinimalFilter of the Channel)." );
                
                Assert.That( g.SetConfiguration( new GrandOutputConfiguration(), TestHelper.ConsoleMonitor ) );
                g.Dispose( TestHelper.ConsoleMonitor );

                m.Info().Send( "After disposing - NOSHOW." );

                Assert.That( m.ActualFilter, Is.EqualTo( LogFilter.Undefined ) ); 
            }
            
        }