Inheritance: AppenderSkeleton
コード例 #1
0
        public static IMongoDatabase GetDatabase(MongoDBAppender appender)
        {
            var mongoUrl = MongoUrl.Create(appender.ConnectionString);
            var client   = new MongoClient(mongoUrl);

            return(client.GetDatabase(mongoUrl.DatabaseName ?? "log4net_mongodb"));
        }
コード例 #2
0
		public static MongoDatabase GetDatabase(MongoDBAppender appender)
		{
			var port = appender.Port > 0 ? appender.Port : 27017;
			var mongoConnectionString = new StringBuilder(string.Format("Server={0}:{1}", appender.Host ?? "localhost", port));
			if(!string.IsNullOrEmpty(appender.UserName) && !string.IsNullOrEmpty(appender.Password))
			{
				// use MongoDB authentication
				mongoConnectionString.AppendFormat(";Username={0};Password={1}", appender.UserName, appender.Password);
			}

			MongoServer connection = MongoServer.Create(mongoConnectionString.ToString());
			connection.Connect();
			return connection.GetDatabase(appender.DatabaseName ?? "log4net_mongodb");
		}