コード例 #1
0
        private void InitializeLogger()
        {
            // Aggiungo il logger, se definita la modalità Auto
            bool result = false;

            if (bool.TryParse(ConfigurationManager.AppSettings["log4net"], out result) && result &&
                bool.TryParse(ConfigurationManager.AppSettings["AutoLog"], out result) && result)
            {
                // Aggiungo il Log del modulo
                var mainAppender = DynamicLoggerConfigurator.AddAppender(ConfigurationModule.Id);
                DynamicLoggerConfigurator.AddLogger(ConfigurationModule.Id, mainAppender, ConfigurationModule.MainLogLevel.ToLevel());

                // Aggiungo il log Threaded
                if (ConfigurationModule.EnableThreadLog)
                {
                    if (ConfigurationModule.MergeLogs)
                    {
                        DynamicLoggerConfigurator.AddLogger(ThreadedModuleLogger, mainAppender,
                                                            ConfigurationModule.ThreadLogLevel.ToLevel());
                    }
                    else
                    {
                        DynamicLoggerConfigurator.AddCompleteLogger(ThreadedModuleLogger, ConfigurationModule.ThreadLogLevel.ToLevel());
                    }
                }

                DynamicLoggerConfigurator.Configured();
            }
        }
コード例 #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            var defaultCulture = ConfigurationManager.AppSettings["DefaultCulture"];

            if (!string.IsNullOrEmpty(defaultCulture))
            {
                var culture = new CultureInfo(defaultCulture);
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }

            //Inizializzo Log4Net
            bool result;

            if (bool.TryParse(ConfigurationManager.AppSettings["log4net"], out result) && result)
            {
                if (bool.TryParse(ConfigurationManager.AppSettings["AutoLog"], out result) && result)
                {
                    BasicConfigurator.Configure();
                    // Aggiungo il Log di JeepService
                    DynamicLoggerConfigurator.AddCompleteLogger("JeepService");

                    // Aggiungo il Log di DocSuite
                    DynamicLoggerConfigurator.AddCompleteLogger("DocSuiteLog", LogLevel.All.ToLevel());

                    // Finalizzo l'impostazione
                    DynamicLoggerConfigurator.Configured();
                }
                else
                {
                    FileLogger.Initialize();
                }
            }

            bool install = false, uninstall = false, console = false, rethrow = false;

            try
            {
                foreach (var arg in args)
                {
                    switch (arg)
                    {
                    case "-i":
                    case "-install":
                        install = true; break;

                    case "-u":
                    case "-uninstall":
                        uninstall = true; break;

                    case "-c":
                    case "-console":
                        console = true; break;
                    }
                }
                if (uninstall)
                {
                    Install(true, args);
                }
                if (install)
                {
                    Install(false, args);
                }
                if (console)
                {
                    Console.WriteLine("Starting...");
                    var service = new JeepService();
                    service.Debug();
                    if (ConsolePresent)
                    {
                        Console.WriteLine("System running; press any key to stop");
                        if (args.Length > 1)
                        {
                            Console.Write("Spegnimento fra {0} sec", args[1]);
                            Thread.Sleep(int.Parse(args[1]) * 1000);
                            service.Stop();
                        }
                        else
                        {
                            Console.ReadKey(true);
                        }
                        Console.WriteLine("System stopped");
                    }
                    else
                    {
                        Thread.Sleep(Timeout.Infinite);
                    }
                }
                else if (!(install || uninstall))
                {
                    rethrow = true; // so that windows sees error...
                    var servicesToRun = new ServiceBase[] { new JeepService() };
                    ServiceBase.Run(servicesToRun);
                    rethrow = false;
                }
                return(0);
            }
            catch (Exception ex)
            {
                if (rethrow)
                {
                    throw;
                }
                Console.Error.WriteLine(ex.Message);
                if (console)
                {
                    Console.ReadLine();
                }
                return(-1);
            }
        }