static void Main(string[] args)
        {
            ILogger logger = new Log4netAdapter(LogManager.GetLogger(ConfigurationProvider.ServiceLoggerName));

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            const string name        = "ControlWorksFaspacService";
            const string description = "Control Works communication service";

            logger.Log(new LogEntry(LoggingEventType.Information, $"Initializing Service {name} - {description}"));

            try
            {
                var host = HostFactory.New(configuration =>
                {
                    configuration.Service <Host>(callback =>
                    {
                        callback.ConstructUsing(s => new Host(logger));
                        callback.WhenStarted(service => service.Start());
                        callback.WhenStopped(service => service.Stop());
                    });
                    configuration.SetDisplayName(name);
                    configuration.SetServiceName(name);
                    configuration.SetDescription(description);
                    configuration.RunAsLocalSystem();
                });
                host.Run();
            }
            catch (Exception ex)
            {
                logger.Log(new LogEntry(LoggingEventType.Fatal, "ControlWorksFaspacService Service fatal exception."));
                logger.Log(new LogEntry(LoggingEventType.Fatal, ex.Message, ex));
            }
        }
Ejemplo n.º 2
0
        private void VerifyLogFile(string logType, LogLevel logLevel, string filePattern, bool shouldLog)
        {
            Log4netAdapter log4netAdapter = new Log4netAdapter(logType);

            string folder = Path.GetFullPath("Logs");
            string[] matches = Directory.GetFiles(folder, filePattern);
            long originalSize = 0, newSize = 0;
            if (matches != null && matches.Length > 0)
            {
                FileInfo originalInfo = new FileInfo(matches[0]);
                originalSize = originalInfo.Length;
            }
            log4netAdapter.Log(logLevel, string.Format("{0} {1}.", logType, logLevel));

            matches = Directory.GetFiles(folder, filePattern);
            if (matches != null && matches.Length > 0)
            {
                FileInfo newInfo = new FileInfo(matches[0]);
                newSize = newInfo.Length;
            }
            if (shouldLog)
                Assert.IsTrue(newSize > originalSize);
            else
                Assert.IsTrue(newSize == originalSize);
        }