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 );
}