public static ClusterBuilder ConfigureLogging(ClusterBuilder builder)
        {
            var environmentVariable = Environment.GetEnvironmentVariable("MONGO_LOGGING");

            if (environmentVariable == null)
            {
                return(builder);
            }

            SourceLevels defaultLevel;

            if (!Enum.TryParse <SourceLevels>(environmentVariable, ignoreCase: true, result: out defaultLevel))
            {
                return(builder);
            }

            __traceSource = new TraceSource("mongodb-tests", defaultLevel);
            __traceSource.Listeners.Clear(); // remove the default listener
#if NETSTANDARD1_6
            var listener = new TextWriterTraceListener(Console.Out);
#else
            var listener = new ConsoleTraceListener();
#endif
            listener.TraceOutputOptions = TraceOptions.DateTime;
            __traceSource.Listeners.Add(listener);
            return(builder.TraceWith(__traceSource));
        }
        public static ClusterBuilder ConfigureLogging(ClusterBuilder builder)
        {
            var traceSource = new TraceSource("mongodb-tests", SourceLevels.Information);

            traceSource.Listeners.Clear(); // remove the default listener
            var listener = new ConsoleTraceListener();

            traceSource.Listeners.Add(listener);
            return(builder.TraceWith(traceSource));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configures a MongoDB client to write its logs to the standard output
        /// </summary>
        private static void ClientSettingsClusterConfigurator(ClusterBuilder cb)
        {
            var traceSource = new TraceSource("~~ MongoDB ~~", SourceLevels.Warning);

            traceSource.Listeners.Clear();
            var listener = new TextWriterTraceListener(Console.Out)
            {
                TraceOutputOptions = TraceOptions.DateTime,
            };

            traceSource.Listeners.Add(listener);
            cb.TraceWith(traceSource);
        }
        public static ClusterBuilder ConfigureCluster(ClusterBuilder builder)
        {
            var serverSelectionTimeoutString = Environment.GetEnvironmentVariable("MONGO_SERVER_SELECTION_TIMEOUT_MS");

            if (serverSelectionTimeoutString == null)
            {
                serverSelectionTimeoutString = "10000";
            }

            builder = builder
                      .ConfigureWithConnectionString(__connectionString)
                      .ConfigureCluster(c => c.With(serverSelectionTimeout: TimeSpan.FromMilliseconds(int.Parse(serverSelectionTimeoutString))));

            if (__connectionString.Ssl.HasValue && __connectionString.Ssl.Value)
            {
                var certificateFilename = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_FILE");
                if (certificateFilename != null)
                {
                    builder.ConfigureSsl(ssl =>
                    {
                        var password = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_PASS");
                        X509Certificate cert;
                        if (password == null)
                        {
                            cert = new X509Certificate2(certificateFilename);
                        }
                        else
                        {
                            cert = new X509Certificate2(certificateFilename, password);
                        }
                        return(ssl.With(
                                   clientCertificates: new[] { cert }));
                    });
                }
            }

            var traceSource = new TraceSource("mongodb-tests", SourceLevels.Information);

            traceSource.Listeners.Clear(); // remove the default listener
            var listener = new ConsoleTraceListener();

            traceSource.Listeners.Add(listener);
            builder = builder.TraceWith(traceSource);

            return(builder);
        }
Exemplo n.º 5
0
        public static ClusterBuilder ConfigureLogging(ClusterBuilder builder)
        {
            var environmentVariable = Environment.GetEnvironmentVariable("MONGO_LOGGING");

            if (environmentVariable == null)
            {
                return(builder);
            }

            SourceLevels defaultLevel;

            if (!Enum.TryParse <SourceLevels>(environmentVariable, ignoreCase: true, result: out defaultLevel))
            {
                return(builder);
            }

            __traceSource = new TraceSource("mongodb-tests", defaultLevel);
            __traceSource.Listeners.Clear();
            return(builder.TraceWith(__traceSource));
        }