Example #1
0
        /// <summary>
        /// Ensures that the <see cref="Default"/> GrandOutput is created (see <see cref="EnsureActiveDefault"/>) and configured with default settings:
        /// only one one channel with its minimal filter sets to Debug with one text file handler that writes .txt files in "<see cref="SystemActivityMonitor.RootLogPath"/>\GrandOutputDefault" directory.
        /// The <see cref="SystemActivityMonitor.RootLogPath"/> must be valid and if a GrandOutput.config file exists inside, it is loaded as the configuration.
        /// If it exists, it must be valid (otherwise an exception is thrown).
        /// Once loaded, the file is monitored and any change that occurs to it dynamically triggers a <see cref="SetConfiguration"/> with the new file.
        /// </summary>
        /// <param name="monitor">An optional monitor.</param>
        static public GrandOutput EnsureActiveDefaultWithDefaultSettings(IActivityMonitor monitor = null)
        {
            lock ( _defaultLock )
            {
                if (_default == null)
                {
                    if (monitor == null)
                    {
                        monitor = new SystemActivityMonitor(true, "GrandOutput")
                        {
                            MinimalFilter = GrandOutputMinimalFilter
                        }
                    }
                    ;
                    using (monitor.OpenGroup(LogLevel.Info, "Attempting Default GrandOutput configuration.", null))
                    {
                        try
                        {
                            SystemActivityMonitor.AssertRootLogPathIsSet();
                            _configPath = SystemActivityMonitor.RootLogPath + "GrandOutput.config";
                            GrandOutputConfiguration def = CreateDefaultConfig();
                            if (!File.Exists(_configPath))
                            {
                                File.WriteAllText(_configPath, _defaultConfig);
                            }
                            if (!def.LoadFromFile(_configPath, monitor))
                            {
                                throw new CKException("Unable to load Configuration file: '{0}'.", _configPath);
                            }
                            GrandOutput output = new GrandOutput();
                            if (!output.SetConfiguration(def, monitor))
                            {
                                throw new CKException("Failed to set Configuration.");
                            }
                            StartMonitoring(monitor);
                            _default = output;
                            ActivityMonitor.AutoConfiguration += m => _default.Register(m);
                        }
                        catch (Exception ex)
                        {
                            monitor.SendLine(LogLevel.Fatal, null, ex);
                            throw;
                        }
                    }
                }
            }
            return(_default);
        }

        const string _defaultConfig =
            @"<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""TextFile"" Name=""All"" Path=""GrandOutputDefault"" MaxCountPerFile=""20000"" />
    </Channel>
</GrandOutputConfiguration>";
Example #2
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 ApplyConfigWithError()
        {
            GrandOutputConfiguration c = new GrandOutputConfiguration();
            Assert.That( c.Load( XDocument.Parse( @"
<GrandOutputConfiguration AppDomainDefaultFilter=""Release"" >
    <Channel>
        <Add Type=""BinaryFile"" Name=""GlobalCatch"" Path=""Configuration/ invalid path? (? is forbidden)"" />
    </Channel>
</GrandOutputConfiguration>"
                ).Root, TestHelper.ConsoleMonitor ) );
            Assert.That( c.ChannelsConfiguration.Configurations.Count, Is.EqualTo( 1 ) );

            GrandOutput g = new GrandOutput();
            Assert.That( g.SetConfiguration( c, TestHelper.ConsoleMonitor ), Is.False );
            Assert.That( g.IsDisposed, Is.False );
            g.Dispose( TestHelper.ConsoleMonitor );
            Assert.That( g.IsDisposed );

        }
 /// <summary>
 /// Ensures that the <see cref="Default"/> GrandOutput is created (see <see cref="EnsureActiveDefault"/>) and configured with default settings:
 /// only one one channel with its minimal filter sets to Debug with one text file handler that writes .txt files in "<see cref="SystemActivityMonitor.RootLogPath"/>\GrandOutputDefault" directory.
 /// The <see cref="SystemActivityMonitor.RootLogPath"/> must be valid and if a GrandOutput.config file exists inside, it is loaded as the configuration.
 /// If it exists, it must be valid (otherwise an exception is thrown).
 /// Once loaded, the file is monitored and any change that occurs to it dynamically triggers a <see cref="SetConfiguration"/> with the new file.
 /// </summary>
 /// <param name="monitor">An optional monitor.</param>
 static public GrandOutput EnsureActiveDefaultWithDefaultSettings( IActivityMonitor monitor = null )
 {
     lock( _defaultLock )
     {
         if( _default == null )
         {
             if( monitor == null ) monitor = new SystemActivityMonitor( true, "GrandOutput" ) { MinimalFilter = GrandOutputMinimalFilter };
             using( monitor.OpenGroup( LogLevel.Info, "Attempting Default GrandOutput configuration.", null ) )
             {
                 try
                 {
                     SystemActivityMonitor.AssertRootLogPathIsSet();
                     _configPath = SystemActivityMonitor.RootLogPath + "GrandOutput.config";
                     GrandOutputConfiguration def = CreateDefaultConfig();
                     if( !File.Exists( _configPath ) )
                     {
                         File.WriteAllText( _configPath, _defaultConfig );
                     }
                     if( !def.LoadFromFile( _configPath, monitor ) )
                     {
                         throw new CKException( "Unable to load Configuration file: '{0}'.", _configPath );
                     }
                     GrandOutput output = new GrandOutput();
                     if( !output.SetConfiguration( def, monitor ) )
                     {
                         throw new CKException( "Failed to set Configuration." );
                     }
                     StartMonitoring( monitor );
                     _default = output;
                     ActivityMonitor.AutoConfiguration += m => _default.Register( m );
                 }
                 catch( Exception ex )
                 {
                     monitor.SendLine( LogLevel.Fatal, null, ex );
                     throw;
                 }
             }
         }
     }
     return _default;
 }
Example #5
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);
 }
Example #6
0
 internal GrandOutputClient( GrandOutput central )
 {
     _central = central;
 }
Example #7
0
 /// <summary>
 /// Creates a MonitorTraceListener instance.
 /// </summary>
 /// <param name="grandOutput">The <see cref="Monitoring.GrandOutput"/> to send traces to.</param>
 /// <param name="failFast">
 /// When true <see cref="Environment.FailFast(string)"/> will terminate the application on <see cref="Debug.Assert(bool)"/>, <see cref="Trace.Assert(bool)"/>,
 /// <see cref="Debug.Fail(string)"/> and <see cref="Trace.Fail(string)"/>.
 /// See this <see cref="MonitorTraceListener"/>'s remarks section to understand why this should be false.
 /// </param>
 public MonitorTraceListener(GrandOutput grandOutput, bool failFast)
 {
     Throw.CheckNotNullArgument(grandOutput);
     GrandOutput = grandOutput;
     FailFast    = failFast;
 }
 internal GrandOutputClient(GrandOutput central)
 {
     _central = central;
 }
        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 ) ); 
            }
            
        }