/// <summary>
        /// Initializes a new instance of the <see cref="LogKernel"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public LogKernel(LogConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration", "Log configuration cannot be null.");
            }

            _lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
            _loggers = new LoggerCollection();

            // Configure the kernel.
            this.Configure(configuration);
        }
        public static void Main(string[] args)
        {
            // Create the configuration.
            LogConfiguration configuration = new LogConfiguration();

            // Add a console sink to the configuration.
            configuration.Sinks.Add(new ConsoleSink { Format = "$(time(format='HH:mm:ss')): $(message())" });

            // Create the log kernel and create a logger.
            LogKernel kernel = new LogKernel(configuration);
            ILogger logger = kernel.GetLogger();

            // Write a message to the logger.
            logger.Write(LogLevel.Information, "Hello World!");

            // Wait for the user to press a key.
            Console.WriteLine("Press ANY key to quit.");
            Console.ReadKey(true);
        }
        private void RegisterLogging()
        {
            var configuration = LogConfiguration.FromConfigSection();
            if (configuration == null)
            {
                configuration = new LogConfiguration();
                configuration.Sinks.Add(new TraceSink());
            }

            // Create the kernel.
            var kernel = new LogKernel(configuration);

            // Register the kernel and loggers in the container.
            _kernel.Bind<ILogKernel>().ToConstant(kernel).InSingletonScope();
            _kernel.Bind<ILogger>().ToMethod(x => x.Kernel.Get<ILogKernel>().GetLogger(x.Request.ParentRequest.Service));
        }
        private void Configure(LogConfiguration configuration)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            using (_lock.AcquireWriteLock())
            {
                if (_configuration != null)
                {
                    // TODO: Dispose the configuration here.
                    throw new NotImplementedException("Configuration should be disposed.");
                }

                // Set the active configuration.
                _configuration = configuration ?? new LogConfiguration();

                // Initialize the configuration.
                IEnumerable<Assembly> assemblies = _configuration.Assemblies;
                IInternalLogger internalLogger = _configuration.InternalLogger;
                using (var context = new InitializationContext(assemblies, internalLogger))
                {
                    _configuration.Initialize(context);
                }
            }
        }
 internal static XDocument Serialize(LogConfiguration configuration)
 {
     LogConfigurationSerializer serializer = new LogConfigurationSerializer(configuration);
     return serializer.Serialize();
 }
 private LogConfigurationSerializer(LogConfiguration configuration)
 {
     _configuration = configuration;
 }