예제 #1
0
파일: Servo.cs 프로젝트: LSTANCZYK/Servo
        public SvcInstaller()
        {
            var processInstaller = new ServiceProcessInstaller {
                Account = ServiceAccount.LocalSystem
            };

            var conf             = new Config();
            var serviceInstaller = new ServiceInstaller
            {
                ServiceName = conf.ServiceName,
                DisplayName = conf.DisplayName,
                StartType   = conf.ServiceStartMode,
                Description = conf.Description
            };

            try
            {
                serviceInstaller.ServicesDependedOn = conf.ServicesDependedOn;
            }
            catch (Exception ex) { ClassLogger.Error(ex); }

            try
            {
                serviceInstaller.DelayedAutoStart = conf.DelayedAutoStart;
            }
            catch (Exception ex) { ClassLogger.Error(ex); }

            Installers.AddRange(new Installer[] { serviceInstaller, processInstaller });
        }
예제 #2
0
파일: Servo.cs 프로젝트: LSTANCZYK/Servo
        public void Stop()
        {
            try
            {
                ClassLogger.Info("Stopping Service...");
                const int timeout = 7 * 60;
                _c.Stop();

                const ServiceControllerStatus targetStatus = ServiceControllerStatus.Stopped;
                _c.WaitForStatus(targetStatus, TimeSpan.FromSeconds(timeout));
            }
            catch (Exception ex)
            {
                ClassLogger.Error("Error in stopping service: {0}", ex);
            }
        }
예제 #3
0
파일: Servo.cs 프로젝트: LSTANCZYK/Servo
        internal static void Install(bool undo, string[] args)
        {
            try
            {
                Console.WriteLine(undo ? "uninstalling" : "installing");

                if (undo)
                {
                    ManagedInstallerClass.InstallHelper(new string[] { "/u", System.Reflection.Assembly.GetAssembly(typeof(SvcInstaller)).Location });
                }
                else
                {
                    ManagedInstallerClass.InstallHelper(new string[] { System.Reflection.Assembly.GetAssembly(typeof(SvcInstaller)).Location });
                }
            }
            catch (Exception ex) { ClassLogger.Error(ex); }
        }
예제 #4
0
        public void TestClassLoggerLevel()
        {
            TheLog.FilterThreshold = LogLevel.Trace;
            TheLog.AddProvider(InMemoryDatabaseProvider.TheOne, LogLevel.Trace);
            var database = InMemoryDatabaseProvider.TheOne;

            var classLogger = new ClassLogger(typeof(LoggingTests));

            classLogger.Trace("Test");
            Assert.AreEqual(LogLevel.Trace, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Debug("Test");
            Assert.AreEqual(LogLevel.Debug, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Info("Test");
            Assert.AreEqual(LogLevel.Info, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Warn("Test");
            Assert.AreEqual(LogLevel.Warn, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Error("Test");
            Assert.AreEqual(LogLevel.Error, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Fatal("Test");
            Assert.AreEqual(LogLevel.Fatal, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);

            classLogger.Log(LogLevel.Debug, "Message");
            Assert.AreEqual(LogLevel.Debug, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
        }
예제 #5
0
        public void TestClassLogger()
        {
            var inMemoryProvider = new InMemoryDatabaseProvider();

            TheLog.AddProvider(inMemoryProvider, LogLevel.Info);
            TheLog.FilterThreshold = LogLevel.Info;

            _logger.Info("Test");
            _logger.Trace("Test2");
            _logger.Error("Test");

            Assert.AreEqual(2, inMemoryProvider.Messages.Count);
            Assert.IsTrue(inMemoryProvider.Messages[0].LogMessage.Category.Contains("LoggingTests"));

            inMemoryProvider.ClearLog();
            _logger.Error("Test", "ABC");
            Assert.IsTrue(inMemoryProvider.Messages[0].LogMessage.Category.Contains("LoggingTests"));
            Assert.IsTrue(inMemoryProvider.Messages[0].LogMessage.Category.Contains("ABC"));
        }