Register() public method

Ensures that a client for this GrandOutput is registered on a monitor.
public Register ( IActivityMonitor monitor ) : GrandOutputClient
monitor IActivityMonitor The monitor onto which a must be registered.
return GrandOutputClient
Example #1
0
 /// <summary>
 /// Ensures that the <see cref="Default"/> GrandOutput is created and that any <see cref="ActivityMonitor"/> that will be created in this
 /// application domain will automatically have a <see cref="GrandOutputClient"/> registered for this Default GrandOutput.
 /// Use <see cref="EnsureActiveDefaultWithDefaultSettings"/> to initially configure this default.
 /// </summary>
 /// <param name="configurator">
 /// Optional action that can configure the default GrandOutput.
 /// If specified will be called after the creation of a new GrandOutput: it will not be called
 /// if a <see cref="Default"/> is already available.
 /// This parameter is optional since you can configure it at any time.
 /// </param>
 /// <returns>The Default GrandOutput.</returns>
 /// <remarks>
 /// This method is thread-safe (a simple lock protects it) and uses a <see cref="ActivityMonitor.AutoConfiguration"/> action
 /// that <see cref="Register"/>s newly created <see cref="ActivityMonitor"/>.
 /// </remarks>
 static public GrandOutput EnsureActiveDefault(Action <GrandOutput> configurator = null)
 {
     lock ( _defaultLock )
     {
         if (_default != null)
         {
             configurator = null;
         }
         else
         {
             SystemActivityMonitor.EnsureStaticInitialization();
             _default = new GrandOutput();
             ActivityMonitor.AutoConfiguration += m => Default.Register(m);
         }
     }
     if (configurator != null)
     {
         configurator(_default);
     }
     return(_default);
 }
        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 ) ); 
            }
            
        }