Ejemplo n.º 1
0
        public void InsertOneMillionAndWait()
        {
            var target = new MongoTarget();
            var repo = target.GetLogRepository();

            // TODO
        }
Ejemplo n.º 2
0
        public static NLogLoggingConfiguration UseMongoTarget(this NLogLoggingConfiguration nlogConf, IConfiguration configuration)
        {
            var targetOption = configuration.GetSection(nameof(NLogNoSqlTargetOptions)).Get <NLogNoSqlTargetOptions>();
            var mongoOption  = configuration.GetSection(nameof(LogStorageOptions)).Get <LogStorageOptions>();

            if (targetOption == null || mongoOption == null)
            {
                throw new NullReferenceException($"Cannot found {nameof(NLogNoSqlTargetOptions)} or {nameof(LogStorageOptions)} from configuration file!");
            }

            var mongoTarget = new MongoTarget()
            {
                Name             = targetOption.Name,
                CollectionName   = targetOption.CollectionName,
                ConnectionString = configuration["MongoDBConnection"],
                DatabaseName     = mongoOption.DatabaseName,
                IncludeDefaults  = true
            };

            nlogConf.AddTarget(mongoTarget);

            foreach (var r in targetOption.Rules)
            {
                var minlevel = LogLevel.FromString(r.MinLevel);
                var maxLevel = LogLevel.FromString(r.MaxLevel);
                nlogConf.AddRule(minlevel, maxLevel, mongoTarget, r.Logger);
            }

            return(nlogConf);
        }
Ejemplo n.º 3
0
        internal bool OnRunScript(EdiViewModel fileToRun, bool saveAsFlag = true)
        {
            var target = new MongoTarget();
            var start  = new ProcessStartInfo();

            var vm = ShowOutput();

            vm.Document.Text = "";
            if (vm.Document.TextEditor == null)
            {
                MessageBox.Show("Output window was not open, can't redirect output.\nPlease try again.", "Status",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return(false);
            }
            if (!Directory.Exists(target.Directory))
            {
                MessageBox.Show("Mongo bin directory was not found.\nPlease configure path in app.config.", "Status",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return(false);
            }
            if (IsOutputFile(fileToRun.FileName))
            {
                MessageBox.Show("Please selct script to run.", "Status",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return(false);
            }

            start.FileName               = target.Executable;
            start.Arguments              = target.Arguments + "\"" + fileToRun.FilePath + "\"";
            start.WorkingDirectory       = target.Directory;
            start.UseShellExecute        = false;
            start.CreateNoWindow         = target.CreateNoWindow;
            start.RedirectStandardOutput = true;

            using (var process = Process.Start(start))
            {
                if (process != null)
                {
                    Redirect(process.StandardOutput, vm);
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        public void TestSettings()
        {
            MongoTarget target = new MongoTarget();

            target.CappedCollectionMaxItems
                .Should().Be(null, "because is the default value");
            target.CappedCollectionSize
                .Should().Be(8589934592, "because is the default value");
            target.ConnectionString
                .Should().Be("mongodb://localhost", "because is the default value");
            target.DatabaseName
                .Should().Be("logs", "because is the default value");
            target.UseCappedCollection
                .Should().Be(true, "because is the default value");
            
            target = new MongoTarget
            {
                DatabaseName = DATABASE_NAME,
                ConnectionString = CONNECTION_STRING,
                UseCappedCollection = USE_CAPPED_COLLECTION,
                CappedCollectionMaxItems = CAPPED_COLLECTION_MAX_ITEMS,
                CappedCollectionSize = CAPPED_COLLECTION_SIZE,
                CollectionName = COLLECTION_NAME,
            };

            target.DatabaseName
                .Should().Be(DATABASE_NAME);
            target.ConnectionString
                .Should().Be(CONNECTION_STRING);
            target.UseCappedCollection
                .Should().Be(USE_CAPPED_COLLECTION);
            target.CappedCollectionMaxItems
                .Should().Be(CAPPED_COLLECTION_MAX_ITEMS);
            target.CappedCollectionSize
                .Should().Be(CAPPED_COLLECTION_SIZE);
            target.CollectionName
                .Should().Be(COLLECTION_NAME);
        }