static void Run(Options options)
        {
            // reconfigure loggers to use a file in the current directory
            // or the file specified by the "Log" commandline parameter
            if (LogManager.Configuration != null)
            {
                var target = (FileTarget)LogManager.Configuration.FindTargetByName("logfile");
                if (target != null)
                {
                    var pathToLog = options.LogFile;
                    if (pathToLog == null)
                    {
                        pathToLog = Path.Combine(Environment.CurrentDirectory, "SqlWorkload.log");
                    }
                    if (!Path.IsPathRooted(pathToLog))
                    {
                        pathToLog = Path.Combine(Environment.CurrentDirectory, pathToLog);
                    }
                    target.FileName = pathToLog;

                    if (options.LogLevel != null)
                    {
                        foreach (var rule in LogManager.Configuration.LoggingRules)
                        {
                            foreach (var level in LogLevel.AllLoggingLevels)
                            {
                                rule.DisableLoggingForLevel(level);
                            }
                            rule.EnableLoggingForLevels(LogLevel.FromString(options.LogLevel), LogLevel.Fatal);
                        }
                    }

                    LogManager.ReconfigExistingLoggers();
                }
            }

            options.ConfigurationFile = System.IO.Path.GetFullPath(options.ConfigurationFile);
            logger.Info(String.Format("Reading configuration from '{0}'", options.ConfigurationFile));

            SqlWorkloadConfig config = SqlWorkloadConfig.LoadFromFile(options.ConfigurationFile);

            config.Controller.Listener.Source = System.IO.Path.GetFullPath(config.Controller.Listener.Source);

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                logger.Info("Received shutdown signal...");
                source.CancelAfter(TimeSpan.FromSeconds(100)); // give a 100 seconds cancellation grace period
                config.Controller.Stop();
            };

            Task t = processController(config.Controller);

            t.Wait();
            logger.Info("Controller stopped.");
            config.Controller.Dispose();
            logger.Info("Controller disposed.");
        }
Exemple #2
0
        static void Run(Options options)
        {
            options.ConfigurationFile = System.IO.Path.GetFullPath(options.ConfigurationFile);
            logger.Info(String.Format("Reading configuration from '{0}'", options.ConfigurationFile));

            SqlWorkloadConfig config = SqlWorkloadConfig.LoadFromFile(options.ConfigurationFile);

            config.Controller.Listener.Source = System.IO.Path.GetFullPath(config.Controller.Listener.Source);

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                logger.Info("Received shutdown signal...");
                source.CancelAfter(TimeSpan.FromSeconds(10)); // give a 10 seconds cancellation grace period
                config.Controller.Stop();
            };

            Task t = processController(config.Controller);

            t.Wait();
            logger.Info("Controller stopped.");
        }