예제 #1
0
        /// <summary>实例</summary>
        static EventLogHelper GetInstance()
        {
            if (instance == null)
            {
                lock (lockObject)
                {
                    if (instance == null)
                    {
                        instance = new EventLogHelper();
                    }
                }
            }

            return(instance);
        }
        /// <summary>启动</summary>
        public static void Start()
        {
            try
            {
                ServicesConfiguration configuration = ServicesConfigurationView.Instance.Configuration;

                foreach (ServiceObserverConfigurationElement observer in configuration.Observers)
                {
                    IServiceObserver serviceObserver = (IServiceObserver)Assembly.Load(observer.TypeName.Substring(observer.TypeName.IndexOf(",") + 1).Trim()).CreateInstance(observer.TypeName.Substring(0, observer.TypeName.IndexOf(",")).Trim(), false, BindingFlags.Default, null, new object[] { observer.Name, observer.Args }, null, null);

                    EventLogHelper.Information("正在创建监听器【" + observer.Name + "】。");

                    if (serviceObserver == null)
                    {
                        EventLogHelper.Error(string.Format("监听器【{0}】初始化类型【{1}】失败,请确认配置是否正确。", observer.Name, observer.TypeName));
                    }
                    else
                    {
                        serviceObserver.Start();

                        serviceObservers.Add(serviceObserver);
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogHelper.Error(ex.ToString());

                throw ex;
            }

            // -------------------------------------------------------
            // 设置定时器
            // -------------------------------------------------------

            timer.Enabled = true;

            timer.Interval = ServicesConfigurationView.Instance.TimerInterval * 1000;

            timer.Elapsed += delegate(object sender, ElapsedEventArgs e)
            {
                ServiceObserverManagement.Run();
            };

            timer.Start();
        }
 public void Pause()
 {
     EventLogHelper.Write(string.Format("{0} 服务被暂停。", this.ServiceName));
 }