CK.Monitoring.GrandOutputConfiguration.Load C# (CSharp) Method

Load() public method

Loads this configuration from a XElement.
public Load ( System.Xml.Linq.XElement e, IActivityMonitor monitor ) : bool
e System.Xml.Linq.XElement The xml element: its name must be GrandOutputConfiguration.
monitor IActivityMonitor Monitor that will be used.
return bool
        public bool Load( XElement e, IActivityMonitor monitor )
        {
            if( e == null ) throw new ArgumentNullException( "e" );
            if( monitor == null ) throw new ArgumentNullException( "monitor" );
            try
            {
                if( e.Name != "GrandOutputConfiguration" ) throw new XmlException( "Element name must be <GrandOutputConfiguration>." + e.GetLineColumnString() );
                // AppDomainDefaultFilter was the name before.
                LogFilter? globalDefaultFilter = e.GetAttributeLogFilter( "GlobalDefaultFilter", false ) 
                                                    ?? e.GetAttributeLogFilter( "AppDomainDefaultFilter", false );

                SourceFilterApplyMode applyMode;
                Dictionary<string, LogFilter> sourceFilter = ReadSourceOverrideFilter( e, out applyMode, monitor );
                if( sourceFilter == null ) return false;

                RouteConfiguration routeConfig;
                using( monitor.OpenGroup( LogLevel.Trace, "Reading root Channel.", null ) )
                {
                    XElement channelElement = e.Element( "Channel" );
                    if( channelElement == null )
                    {
                        monitor.SendLine( LogLevel.Error, "Missing <Channel /> element." + e.GetLineColumnString(), null );
                        return false;
                    }
                    routeConfig = FillRoute( monitor, channelElement, new RouteConfiguration() );
                }
                // No error: set the new values.
                _routeConfig = routeConfig;
                _sourceFilter = sourceFilter;
                _sourceFilterApplyMode = applyMode;
                _globalDefaultFilter = globalDefaultFilter;
                return true;
            }
            catch( Exception ex )
            {
                monitor.SendLine( LogLevel.Error, null, ex );
            }
            return false;
        }

Usage Example

 public void ConfigObjectAttributeRequired()
 {
     GrandOutputConfiguration c = new GrandOutputConfiguration();
     Assert.That( c.Load( XDocument.Parse( @"<GrandOutputConfiguration><Add /></GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor ), Is.False );
     Assert.That( c.Load( XDocument.Parse( @"<GrandOutputConfiguration><Channel><Add Type=""BinaryFile"" /></Channel></GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor ), Is.False );
     Assert.That( c.Load( XDocument.Parse( @"<GrandOutputConfiguration><Channel><Add Type=""BinaryFile"" Name=""GlobalCatch"" /></Channel></GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor ), Is.False );
     // This is okay: Type, Name and Path for BinaryFile.
     Assert.That( c.Load( XDocument.Parse( @"<GrandOutputConfiguration><Channel><Add Type=""BinaryFile"" Name=""GlobalCatch"" Path=""In-Root-Log-Path"" /></Channel></GrandOutputConfiguration>" ).Root, TestHelper.ConsoleMonitor ) );
 }
All Usage Examples Of CK.Monitoring.GrandOutputConfiguration::Load