示例#1
0
        /// <summary>
        /// The entry point for the application.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        /// <returns>Exit code indicating whether program execution was successful.</returns>
        private static int Main(string[] args)
        {
            // Enable TLS v1.2 for the whole application
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // Store CWD in case the executing assembly is being run from the system PATH.
            var currentWorkingDirectory = Environment.CurrentDirectory;

            // Initialize log4net settings.
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;

            Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyLocation));
            try
            {
                XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings[Log4NetConfigKey]));
            }
            catch (Exception ex)
            {
                Log.FatalFormat($"Failed to initialize logging: {ex.Message}");
                return((int)ExitCode.InitializationError);
            }

            // Parse command line args.
            Log.DebugFormat($"Logshark execution arguments: {string.Join(" ", args)}");
            var options = new LogsharkCommandLineOptions();

            if (!Parser.Default.ParseArgumentsStrict(args, options, () => Log.Fatal("Unable to parse the provided arguments. Please check your syntax and try again.")))
            {
                // Parsing failed, exit with failure code.
                return((int)ExitCode.ArgumentParsingError);
            }

            // Execute!
            try
            {
                var logsharkCli = new LogsharkCLI(currentWorkingDirectory);
                return((int)logsharkCli.Execute(options));
            }
            catch (Exception)
            {
                return((int)ExitCode.ExecutionError);
            }
        }
示例#2
0
        /// <summary>
        /// The entry point for the application.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        /// <returns>0 if program execution was successful; 1 otherwise.</returns>
        private static int Main(string[] args)
        {
            // Store CWD in case the executing assembly is being run from the system PATH.
            string currentWorkingDirectory = Environment.CurrentDirectory;

            // Initialize log4net settings.
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;

            Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyLocation));
            try
            {
                XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings[Log4NetConfigKey]));
            }
            catch (Exception ex)
            {
                Log.FatalFormat("Failed to initialize logging: {0}", ex.Message);
                return(1);
            }

            // Parse command line args.
            Log.DebugFormat("Logshark execution arguments: {0}", String.Join(" ", args));
            LogsharkCommandLineOptions options = new LogsharkCommandLineOptions();

            if (!Parser.Default.ParseArgumentsStrict(args, options))
            {
                // Parsing failed, exit with failure code.
                return(1);
            }

            // Execute!
            try
            {
                var logsharkCli = new LogsharkCLI(options, currentWorkingDirectory);
                logsharkCli.Execute();
                return(0);
            }
            catch (Exception)
            {
                return(1);
            }
        }