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 ); } }
/// <summary> /// Ensures that any groups opened after this one are closed before closing this one. /// </summary> void IDisposable.Dispose() { if (_data != null) { while (Monitor._current != this) { ((IDisposable)Monitor._current).Dispose(); } Monitor.CloseGroup(Monitor.NextLogTime(), null); } }
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." ); }