/// <summary> /// Log the message with exception. /// </summary> /// <param name="type">The type of the logger.</param> /// <param name="level">The level of the log.</param> /// <param name="message">The message to be logged.</param> /// <param name="parameters">The parameters used to format the message.</param> /// <param name="rootException">The exception to be logged.</param> public static void Log(LoggerType type, LogLevel level, string message, object[] parameters, Exception rootException) { Logger logger = LoggerPool.GetLogger(type); if (logger != null) { logger.Log(level, message, parameters, rootException); } }
/// <summary> /// Start the module. /// </summary> public override void Start() { base.Start(); try { ServiceHost = new ServiceHost(typeof(ClientConnectorReal)); //autofac DI ServiceHost.AddDependencyInjectionBehavior <IClientConnector>(IocManager.Container); //绑定服务行为 ServiceMetadataBehavior behavior = ServiceHost.Description.Behaviors. Find <ServiceMetadataBehavior>(); if (behavior == null) { behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; ServiceHost.Description.Behaviors.Add(behavior); } else { behavior.HttpGetEnabled = true; } //启动事件 ServiceHost.Opened += delegate { var Logger = LoggerPool.GetLogger(""); Logger.Info("Host-->Endpoint:" + ServiceHost.Description.Endpoints.FirstOrDefault().Address); Logger.Info("Host-->Service started:" + ServiceHost.Description.ConfigurationName); }; ServiceHost.Closed += delegate { var Logger = LoggerPool.GetLogger(""); Logger.Info("Host-->Endpoint:" + ServiceHost.Description.Endpoints.FirstOrDefault().Address); Logger.Info("Host-->Service closed:" + ServiceHost.Description.ConfigurationName); }; Thread th = new Thread(ServiceHost.Open); th.Start(); IocManager.Register <IServiceHostProvider>(new DefaultServiceHostProvider(ServiceHost)); } catch (Exception ex) { var Logger = LoggerPool.GetLogger(""); Logger.Error(ex.Message, ex); } }
/// <summary> /// Stop the module. /// </summary> public override void Stop() { if (ServiceHost != null) { try { ServiceHost.Close(); } catch (Exception ex) { var Logger = LoggerPool.GetLogger(""); Logger.Error(ex.Message, ex); } finally { ServiceHost.Abort(); } } }
public virtual void Initialize() { LoggerPool?.GetLogger("").Info(Name + " Initialize..."); }
public virtual void Stop() { LoggerPool?.GetLogger("").Info(Name + " Stop..."); }