void BuildContainer(LogViewerConfiguration config) { _container = new WindsorContainer(); _container.Register(Component.For <LogViewerConfiguration>().Instance(config)); _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true)); _container.Kernel.Resolver.AddSubResolver(new ArrayResolver(_container.Kernel, true)); _container.AddFacility <LoggingFacility>(config.CreateLoggingFacility); _logger = _container.Resolve <ILoggerFactory>().Create(GetType()); }
public Boolean Start(LogViewerConfiguration config) { try { _serverAddressList = config .ServerAddressList.Split(',') .ToList(); BuildContainer(config); ContainerAccessor.Instance = _container; if (_logger.IsDebugEnabled) { _logger.Debug("Log viewer starting"); } _container.Install(new ApiInstaller()); var url = new MongoUrl(config.MongoDbConnection); var client = new MongoClient(url); var mongoDb = client.GetServer().GetDatabase(url.DatabaseName); _container.Register(Component.For <MongoDatabase>().Instance(mongoDb)); _container.Register( Component.For <MongoCollection>().Instance(mongoDb.GetCollection(config.MongoDbDefaultCollectionLog))); StartOptions options = new StartOptions(); foreach (var address in _serverAddressList) { options.Urls.Add(address); } _webApplication = WebApp.Start <LogViewerApplication>(options); _logger.InfoFormat("Started server @ {0}", _serverAddressList.Aggregate((s1, s2) => s1 + ", " + s2)); } catch (Exception ex) { Console.Error.WriteLine("Exception: " + ex.ToString()); Console.Error.WriteLine("Press a key to continue"); Console.ReadKey(); throw; } return(true); }