Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class.
        /// </summary>
        /// <param name="rootConfig">The root config.</param>
        /// <param name="appServers">The app servers.</param>
        /// <param name="logFactory">The log factory.</param>
        public DefaultBootstrap(IRootConfig rootConfig, IEnumerable <IWorkItem> appServers, ILogFactory logFactory)
        {
            if (rootConfig == null)
            {
                throw new ArgumentNullException("rootConfig");
            }

            if (appServers == null)
            {
                throw new ArgumentNullException("appServers");
            }

            if (!appServers.Any())
            {
                throw new ArgumentException("appServers must have one item at least", "appServers");
            }

            if (logFactory == null)
            {
                throw new ArgumentNullException("logFactory");
            }

            m_RootConfig = rootConfig;

            m_AppServers = appServers.ToList();

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            if (!rootConfig.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, logFactory);
            }

            m_Initialized = true;
        }
Exemple #2
0
        internal static ILog GetCurrentClassLog(this ILogFactory factory, int stackFrameDepth)
        {
            var frame = new StackFrame(stackFrameDepth, false);
            var type  = frame.GetMethod().DeclaringType;
            var log   = factory.GetLog(type);

            return(log);
        }
Exemple #3
0
        /// <summary>
        /// Initializes the specified log factory.
        /// </summary>
        /// <param name="logFactory">The log factory.</param>
        public static void Initialize(ILogFactory logFactory)
        {
            if (m_Initialized)
                throw new Exception("The LogFactoryProvider has been initialized, you cannot initialize it again!");

            m_LogFactory = logFactory;
            GlobalLog = m_LogFactory.GetLog("Global");
            m_Initialized = true;
        }
Exemple #4
0
        public static ILog GetLog(this ILogFactory factory, Type type)
        {
            var name = type
                       .GetTypeName(fullName: true, includeGenerics: false)
                       .TurnToCSharpIdentifier(allowDots: true, avoidKeywords: false);
            var log = factory.GetLog(name);

            return(log);
        }
Exemple #5
0
        public static void Configure(ILogFactory logFactory)
        {
            RealLogFactory = logFactory;
            foreach (KeyValuePair <Type, LogWrapper> logEntry in RegisteredLogs)
            {
                ILog realLog = RealLogFactory != null?logFactory.GetLog(logEntry.Value) : null;

                logEntry.Value.RealLog = realLog;
            }
        }
Exemple #6
0
        public async Task <string> WriteLog(string content)
        {
            var nlog = _logFactory.GetLog(LogConst.DefaultNLogName);

            nlog.Class(this.GetType().FullName).Caption("NLog日志").Content(content).Info();

            var log4Net = _logFactory.GetLog(LogConst.DefaultLog4NetName);

            log4Net.Class(this.GetType().FullName).Caption("Log4net日志").Content(content).Info();

            var serilog = _logFactory.GetLog(LogConst.DefaultSerilogName);

            serilog.Class(this.GetType().FullName).Caption("Serilog日志").Content(content).Info();

            var exceptionless = _logFactory.GetLog(LogConst.DefaultExceptionlessName);

            exceptionless.Class(this.GetType().FullName).Caption("exceptionless日志").Content(content).Info();

            return(await Task.FromResult(content));
        }
        /// <summary>
        /// Initializes the specified log factory.
        /// </summary>
        /// <param name="logFactory">The log factory.</param>
        public static void Initialize(ILogFactory logFactory)
        {
            if (m_Initialized)
            {
                throw new Exception("The LogFactoryProvider has been initialized, you cannot initialize it again!");
            }

            m_LogFactory  = logFactory;
            GlobalLog     = m_LogFactory.GetLog("Global");
            m_Initialized = true;
        }
Exemple #8
0
 public static ILog GetLogger(Type t)
 {
     if (!RegisteredLogs.ContainsKey(t))
     {
         RegisteredLogs[t] = new LogWrapper(Assembly.GetCallingAssembly(), t);
         if (RealLogFactory != null)
         {
             RegisteredLogs[t].RealLog = RealLogFactory.GetLog(RegisteredLogs[t]);
         }
     }
     return(RegisteredLogs[t]);
 }
Exemple #9
0
        public static ILog GetCurrentTypeSectionLog(this ILogFactory applicationLog, string sectionName)
        {
            var stackFrame = new StackFrame(1, false);
            var type       = stackFrame.GetMethod().DeclaringType;
            var name       = $"{type.FullName}.{sectionName}";
            var log        = applicationLog.GetLog(name);

            //if (log is DefaultLog.Log foundationLog)
            //    foundationLog.LoggedName = $"{type.Name}.{sectionName}";

            return(log);
        }
Exemple #10
0
 void InitLogger(string loggerName)
 {
     if (_logFactory == null)
     {
         _logFactory = new Log4NetLogFactory();
     }
     if (String.IsNullOrEmpty(loggerName))
     {
         loggerName = this.GetType().Name;
     }
     _logger = _logFactory.GetLog(loggerName);
 }
        public PerformanceMonitor(IRootConfig config, IEnumerable<IWorkItem> appServers, IWorkItem serverManager, ILogFactory logFactory)
        {
            m_PerfLog = logFactory.GetLog("Performance");

            m_AppServers = appServers.ToArray();

            m_ServerManager = serverManager;

            m_Helper = new ProcessPerformanceCounterHelper(Process.GetCurrentProcess());

            m_TimerInterval = config.PerformanceDataCollectInterval * 1000;
            m_PerformanceTimer = new Timer(OnPerformanceTimerCallback);
        }
Exemple #12
0
        public PerformanceMonitor(IRootConfig config, IEnumerable <IManagedApp> appServers, IManagedApp serverManager, ILogFactory logFactory)
        {
            m_PerfLog = logFactory.GetLog("Performance");

            m_AppServers = appServers.ToArray();

            m_ServerManager = serverManager;

            m_Helper = new ProcessPerformanceCounterHelper(Process.GetCurrentProcess());

            m_TimerInterval    = config.PerformanceDataCollectInterval * 1000;
            m_PerformanceTimer = new Timer(OnPerformanceTimerCallback);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class.
        /// </summary>
        /// <param name="rootConfig">The root config.</param>
        /// <param name="appServers">The app servers.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <param name="serviceProvider">A container for service objects.</param>
        public DefaultBootstrap(IRootConfig rootConfig, IEnumerable <IWorkItem> appServers, ILogFactory logFactory, IServiceProvider serviceProvider)
            : this(serviceProvider)
        {
            if (rootConfig == null)
            {
                throw new ArgumentNullException("rootConfig");
            }

            if (appServers == null)
            {
                throw new ArgumentNullException("appServers");
            }

            if (!appServers.Any())
            {
                throw new ArgumentException("appServers must have one item at least", "appServers");
            }

            if (logFactory == null)
            {
                throw new ArgumentNullException("logFactory");
            }

            m_RootConfig = rootConfig;

            SetDefaultCulture(rootConfig);

            m_AppServers = appServers.ToList();

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (!rootConfig.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, null, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                {
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
                }
            }

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The Bootstrap has been initialized!");
            }

            m_Initialized = true;
        }
Exemple #14
0
    public static ILog GetTypeLog(this ILogFactory logFactory, Type type)
    {
        ArgumentNullException.ThrowIfNull(logFactory);
        ArgumentNullException.ThrowIfNull(type);

        var name = type.FullName;

        var log = logFactory.GetLog(name);

        //if (log is DefaultLog.Log foundationLog)
        //    foundationLog.LoggedName = type.Name;

        return(log);
    }
Exemple #15
0
        public static ILog GetTypeLog(this ILogFactory logFactory, Type type)
        {
            Assert.IsNotNull(logFactory);
            Assert.IsNotNull(type);

            var name = type.FullName;

            var log = logFactory.GetLog(name);

            //if (log is DefaultLog.Log foundationLog)
            //    foundationLog.LoggedName = type.Name;

            return(log);
        }
Exemple #16
0
        /// <summary> Gets a named  <see cref="ILog" /> instance. This is the logger instance set by the <see cref="SetLog" /> method, or a logger with the specified name if a factory can be resolved that
        ///     returns. </summary>
        /// <param name="name"> The name of the requested logger. If this parameter is a null reference, the <see cref="DefaultLogName" /> will be used instead. </param>
        /// <returns> Always returns a valid <see cref="ILog" /> instance. If no log can be resolved, an instance of <see cref="NullLogger" /> is returned. </returns>
        /// <remarks> This method applies several fallback strategies when trying to determine the requested log. </remarks>
        public static ILog GetLog(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = DefaultLogName;
            }

            //the name is used to resolve both the factory...
            ILogFactory factory = FactoryResolver.GetFactory(name);

            if (factory == null)
            {
                return(NullLog.Instance);
            }

            //...and logger instance
            return(factory.GetLog(name) ?? NullLog.Instance);
        }
Exemple #17
0
        public PerformanceMonitor(IRootConfig config, IEnumerable <IWorkItem> appServers, ILogFactory logFactory)
        {
            m_PerfLog = logFactory.GetLog("Performance");

            m_AppServers = appServers.ToArray();

            Process process = Process.GetCurrentProcess();

            m_CpuCores = Environment.ProcessorCount;

            var isUnix       = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
            var instanceName = (isUnix || Platform.IsMono) ? string.Format("{0}/{1}", process.Id, process.ProcessName) : GetPerformanceCounterInstanceName(process);

            SetupPerformanceCounters(instanceName);

            m_TimerInterval    = config.PerformanceDataCollectInterval * 1000;
            m_PerformanceTimer = new Timer(OnPerformanceTimerCallback);
        }
        public PerformanceMonitor(IRootConfig config, IEnumerable<IWorkItem> appServers, ILogFactory logFactory)
        {
            m_PerfLog = logFactory.GetLog("Performance");

            m_AppServers = appServers.ToArray();

            Process process = Process.GetCurrentProcess();

            m_CpuCores = Environment.ProcessorCount;

            var isUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
            var instanceName = (isUnix || Platform.IsMono) ? string.Format("{0}/{1}", process.Id, process.ProcessName) : GetPerformanceCounterInstanceName(process);

            SetupPerformanceCounters(instanceName);

            m_TimerInterval = config.PerformanceDataCollectInterval * 1000;
            m_PerformanceTimer = new Timer(OnPerformanceTimerCallback);
        }
Exemple #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="applicationLog"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static ILog GetCurrentMethodLog(this ILogFactory applicationLog, params object[] parameters)
        {
            var stackFrame = new StackFrame(1, false);
            var method     = stackFrame.GetMethod();
            var type       = method.DeclaringType;
            var name       = $"{type.FullName}.{method.Name}";
            var log        = applicationLog.GetLog(name);

            if (log is FoundationLog foundationLog)
            {
                foundationLog.LoggedName = $"{type.Name}.{method.Name}";
            }

            if (parameters.Length > 0)
            {
                var parameterInfos = method.GetParameters();
                var sb             = new StringBuilder();
                sb.AppendFormat("Entering method {0}(", method.Name);
                var count = Math.Min(parameterInfos.Length, parameters.Length);

                for (var i = 0; i < count; i++)
                {
                    var parameterInfo = parameterInfos[i];
                    sb.AppendFormat("\r\n{0} {1}", parameterInfo.ParameterType.Name, parameterInfo.Name);
                    if (i < parameters.Length)
                    {
                        sb.Append(" = ");
                        var parameterString = ParameterValueToString(parameters[i]);
                        sb.Append(parameterString);
                    }

                    if (i < count - 1)
                    {
                        sb.Append(',');
                    }
                }

                sb.Append(')');
                var message = sb.ToString();
                log.Trace(message);
            }

            return(log);
        }
        public PerformanceMonitor(IRootConfig config, IEnumerable <IWorkItem> appServers, ILogFactory logFactory)
        {
            m_AppServers = appServers.ToArray();

            Process process = Process.GetCurrentProcess();

            m_CpuCores = Environment.ProcessorCount;

            var isUnix       = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
            var instanceName = isUnix ? string.Format("{0}/{1}", process.Id, process.ProcessName) : process.ProcessName;

            m_CpuUsagePC    = new PerformanceCounter("Process", "% Processor Time", instanceName);
            m_ThreadCountPC = new PerformanceCounter("Process", "Thread Count", instanceName);
            m_WorkingSetPC  = new PerformanceCounter("Process", "Working Set", instanceName);

            m_PerfLog = logFactory.GetLog("performance");

            m_TimerInterval    = config.PerformanceDataCollectInterval * 1000;
            m_PerformanceTimer = new Timer(OnPerformanceTimerCallback);
        }
        public PerformanceMonitor(IRootConfig config, IEnumerable<IWorkItem> appServers, ILogFactory logFactory)
        {
            m_AppServers = appServers.ToArray();

            Process process = Process.GetCurrentProcess();

            m_CpuCores = Environment.ProcessorCount;

            var isUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
            var instanceName = isUnix ? string.Format("{0}/{1}", process.Id, process.ProcessName) : process.ProcessName;

            m_CpuUsagePC = new PerformanceCounter("Process", "% Processor Time", instanceName);
            m_ThreadCountPC = new PerformanceCounter("Process", "Thread Count", instanceName);
            m_WorkingSetPC = new PerformanceCounter("Process", "Working Set", instanceName);

            m_PerfLog = logFactory.GetLog("Performance");

            m_TimerInterval = config.PerformanceDataCollectInterval * 1000;
            m_PerformanceTimer = new Timer(OnPerformanceTimerCallback);
        }
Exemple #22
0
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func <IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
            {
                throw new Exception("The server had been initialized already, you cannot initialize it again!");
            }

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            if (logFactory == null)
            {
                logFactory = GetBootstrapLogFactory(m_Config.LogFactory);
            }

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            m_AppServers = new List <IManagedApp>(m_Config.Servers.Count());

            IManagedApp serverManager = null;

            //Initialize servers
            foreach (var config in m_Config.Servers)
            {
                var serverConfig = config;

                if (serverConfigResolver != null)
                {
                    serverConfig = serverConfigResolver(config);
                }

                IManagedApp appServer;

                try
                {
                    var serverType = serverConfig.ServerType;

                    if (string.IsNullOrEmpty(serverType) && !string.IsNullOrEmpty(serverConfig.ServerTypeName))
                    {
                        var serverTypeProvider = m_Config.ServerTypes.FirstOrDefault(
                            t => t.Name.Equals(serverConfig.ServerTypeName, StringComparison.OrdinalIgnoreCase));

                        if (serverTypeProvider != null)
                        {
                            serverType = serverTypeProvider.Type;
                        }
                    }

                    if (string.IsNullOrEmpty(serverType))
                    {
                        throw new Exception("No server type configured or the configured server type was not found.");
                    }

                    appServer = CreateWorkItemInstance(serverType);

                    var serverMetadata = appServer.GetAppServerMetadata();

                    if (serverMetadata.IsServerManager)
                    {
                        serverManager = appServer;
                    }

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been created!", serverConfig.Name);
                    }
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", serverConfig.Name), e);
                    }
                    return(false);
                }

                var exceptionSource = appServer as IExceptionSource;

                if (exceptionSource != null)
                {
                    exceptionSource.ExceptionThrown += new EventHandler <ErrorEventArgs>(exceptionSource_ExceptionThrown);
                }


                var setupResult = false;

                try
                {
                    setupResult = SetupWorkItemInstance(appServer, serverConfig);

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
                    }
                }
                catch (Exception e)
                {
                    m_GlobalLog.Error(e);
                    setupResult = false;
                }

                if (!setupResult)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error("Failed to setup server instance!");
                    }
                    return(false);
                }

                m_AppServers.Add(appServer);
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, serverManager, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                {
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
                }
            }

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The Bootstrap has been initialized!");
            }

            try
            {
                RegisterRemotingService();
            }
            catch (Exception e)
            {
                if (m_GlobalLog.IsErrorEnabled)
                {
                    m_GlobalLog.Error("Failed to register remoting access service!", e);
                }

                return(false);
            }

            m_Initialized = true;

            return(true);
        }
Exemple #23
0
 /// <summary>
 /// Gets the logger.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public static ILog GetLogger(string name)
 {
     return(logFactory.GetLog(name));
 }
Exemple #24
0
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func <IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
            {
                throw new Exception("The server had been initialized already, you cannot initialize it again!");
            }

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            IEnumerable <WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
            {
                var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();

                logFactory = bootstrapLogFactory.ExportFactory.CreateExport <ILogFactory>();

                LogFactory  = logFactory;
                m_GlobalLog = logFactory.GetLog(this.GetType().Name);

                try
                {
                    workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(e);
                    }

                    return(false);
                }
            }

            m_AppServers = new List <IWorkItem>(m_Config.Servers.Count());
            //Initialize servers
            foreach (var factoryInfo in workItemFactories)
            {
                IWorkItem appServer;

                try
                {
                    appServer = CreateWorkItemInstance(factoryInfo.ServerType);

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been created!", factoryInfo.Config.Name);
                    }
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", factoryInfo.Config.Name), e);
                    }
                    return(false);
                }


                var setupResult = false;

                try
                {
                    setupResult = SetupWorkItemInstance(appServer, factoryInfo);

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
                    }
                }
                catch (Exception e)
                {
                    m_GlobalLog.Error(e);
                    setupResult = false;
                }

                if (!setupResult)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error("Failed to setup server instance!");
                    }
                    return(false);
                }

                m_AppServers.Add(appServer);
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                {
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
                }
            }

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The Bootstrap has been initialized!");
            }

            m_Initialized = true;

            return(true);
        }
Exemple #25
0
 /// <summary>
 /// Creates the logger for the AppServer.
 /// </summary>
 /// <param name="loggerName">Name of the logger.</param>
 /// <returns></returns>
 protected virtual ILog CreateLogger(string loggerName)
 {
     return(LogFactory.GetLog(loggerName));
 }
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
                throw new Exception("The server had been initialized already, you cannot initialize it again!");

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            if(logFactory == null)
            {
                logFactory = GetBootstrapLogFactory(m_Config.LogFactory);
            }

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            m_AppServers = new List<IManagedApp>(m_Config.Servers.Count());

            IManagedApp serverManager = null;

            //Initialize servers
            foreach (var serverConfig in m_Config.Servers)
            {
                IManagedApp appServer;

                try
                {
                    var serverType = serverConfig.ServerType;

                    if(string.IsNullOrEmpty(serverType) && !string.IsNullOrEmpty(serverConfig.ServerTypeName))
                    {
                        var serverTypeProvider = m_Config.ServerTypes.FirstOrDefault(
                            t => t.Name.Equals(serverConfig.ServerTypeName, StringComparison.OrdinalIgnoreCase));

                        if (serverTypeProvider != null)
                            serverType = serverTypeProvider.Type;
                    }

                    if (string.IsNullOrEmpty(serverType))
                        throw new Exception("No server type configured or the configured server type was not found.");

                    appServer = CreateWorkItemInstance(serverType);

                    var serverMetadata = appServer.GetAppServerMetadata();

                    if (serverMetadata.IsServerManager)
                        serverManager = appServer;

                    if (m_GlobalLog.IsDebugEnabled)
                        m_GlobalLog.DebugFormat("The server instance {0} has been created!", serverConfig.Name);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                        m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", serverConfig.Name), e);
                    return false;
                }

                var exceptionSource = appServer as IExceptionSource;

                if(exceptionSource != null)
                    exceptionSource.ExceptionThrown += new EventHandler<ErrorEventArgs>(exceptionSource_ExceptionThrown);

                var setupResult = false;

                try
                {
                    setupResult = SetupWorkItemInstance(appServer, serverConfig);

                    if (m_GlobalLog.IsDebugEnabled)
                        m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
                }
                catch (Exception e)
                {
                    m_GlobalLog.Error(e);
                    setupResult = false;
                }

                if (!setupResult)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                        m_GlobalLog.Error("Failed to setup server instance!");
                    return false;
                }

                m_AppServers.Add(appServer);
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, serverManager, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
            }

            if (m_GlobalLog.IsDebugEnabled)
                m_GlobalLog.Debug("The Bootstrap has been initialized!");

            try
            {
                RegisterRemotingService();
            }
            catch (Exception e)
            {
                if (m_GlobalLog.IsErrorEnabled)
                    m_GlobalLog.Error("Failed to register remoting access service!", e);

                return false;
            }

            m_Initialized = true;

            return true;
        }
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
                throw new Exception("The server had been initialized already, you cannot initialize it again!");

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            IEnumerable<WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
            {
                var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();

                logFactory = bootstrapLogFactory.ExportFactory.CreateExport<ILogFactory>();

                LogFactory = logFactory;
                m_GlobalLog = logFactory.GetLog(this.GetType().Name);

                try
                {
                    workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                        m_GlobalLog.Error(e);

                    return false;
                }
            }

            m_AppServers = new List<IWorkItem>(m_Config.Servers.Count());
            //Initialize servers
            foreach (var factoryInfo in workItemFactories)
            {
                IWorkItem appServer;

                try
                {
                    appServer = CreateWorkItemInstance(factoryInfo.ServerType);

                    if (m_GlobalLog.IsDebugEnabled)
                        m_GlobalLog.DebugFormat("The server instance {0} has been created!", factoryInfo.Config.Name);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                        m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", factoryInfo.Config.Name), e);
                    return false;
                }


                var setupResult = false;

                try
                {
                    setupResult = SetupWorkItemInstance(appServer, factoryInfo);

                    if (m_GlobalLog.IsDebugEnabled)
                        m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
                }
                catch (Exception e)
                {
                    m_GlobalLog.Error(e);
                    setupResult = false;
                }

                if (!setupResult)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                        m_GlobalLog.Error("Failed to setup server instance!");
                    return false;
                }

                m_AppServers.Add(appServer);
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
            }

            if (m_GlobalLog.IsDebugEnabled)
                m_GlobalLog.Debug("The Bootstrap has been initialized!");

            m_Initialized = true;

            return true;
        }
Exemple #28
0
        public static ILog GetLog <T>(this ILogFactory factory)
        {
            var log = factory.GetLog(typeof(T));

            return(log);
        }
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func <IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
            {
                throw new Exception("The server had been initialized already, you cannot initialize it again!");
            }

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            IEnumerable <WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
            {
                var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();

                logFactory = bootstrapLogFactory.ExportFactory.CreateExport <ILogFactory>();

                LogFactory  = logFactory;
                m_GlobalLog = logFactory.GetLog(this.GetType().Name);

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                try
                {
                    workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(e);
                    }

                    return(false);
                }
            }

            m_AppServers = new List <IWorkItem>(m_Config.Servers.Count());

            IWorkItem serverManager = null;

            //Initialize servers
            foreach (var factoryInfo in workItemFactories)
            {
                IWorkItem appServer = InitializeAndSetupWorkItem(factoryInfo);

                if (appServer == null)
                {
                    return(false);
                }

                if (factoryInfo.IsServerManager)
                {
                    serverManager = appServer;
                }
                else if (!(appServer is IsolationAppServer))//No isolation
                {
                    //In isolation mode, cannot check whether is server manager in the factory info loader
                    if (TypeValidator.IsServerManagerType(appServer.GetType()))
                    {
                        serverManager = appServer;
                    }
                }

                m_AppServers.Add(appServer);
            }

            if (serverManager != null)
            {
                m_ServerManager = serverManager;
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, serverManager, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                {
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
                }
            }

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The Bootstrap has been initialized!");
            }

            try
            {
                RegisterRemotingService();
            }
            catch (Exception e)
            {
                if (m_GlobalLog.IsErrorEnabled)
                {
                    m_GlobalLog.Error("Failed to register remoting access service!", e);
                }

                return(false);
            }

            m_Initialized = true;

            return(true);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class.
        /// </summary>
        /// <param name="rootConfig">The root config.</param>
        /// <param name="appServers">The app servers.</param>
        /// <param name="logFactory">The log factory.</param>
        public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IWorkItem> appServers, ILogFactory logFactory)
        {
            if (rootConfig == null)
                throw new ArgumentNullException("rootConfig");

            if (appServers == null)
                throw new ArgumentNullException("appServers");

            if(!appServers.Any())
                throw new ArgumentException("appServers must have one item at least", "appServers");

            if (logFactory == null)
                throw new ArgumentNullException("logFactory");

            m_RootConfig = rootConfig;

            m_AppServers = appServers.ToList();

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            if (!rootConfig.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, logFactory);
                m_PerfMonitor.Collected += new EventHandler<PermformanceDataEventArgs>(m_PerfMonitor_Collected);
            }

            m_Initialized = true;
        }
Exemple #31
0
 public static ILog GetLog()
 {
     return(_log ?? _logFactory.GetLog());
 }
Exemple #32
0
 /// <summary> Gets the internal log that is used to output debug information in case something went wrong within this facade. </summary>
 /// <param name="logName"> Requested log name. </param>
 /// <returns> A log that outputs this facade's internal debug information. </returns>
 internal static ILog GetDiagnosticLog(string logName)
 {
     return(diagnosticLogFactory.GetLog(logName));
 }
Exemple #33
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class.
        /// </summary>
        /// <param name="rootConfig">The root config.</param>
        /// <param name="appServers">The app servers.</param>
        /// <param name="logFactory">The log factory.</param>
        public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IWorkItem> appServers, ILogFactory logFactory)
        {
            if (rootConfig == null)
                throw new ArgumentNullException("rootConfig");

            if (appServers == null)
                throw new ArgumentNullException("appServers");

            if(!appServers.Any())
                throw new ArgumentException("appServers must have one item at least", "appServers");

            if (logFactory == null)
                throw new ArgumentNullException("logFactory");

            m_RootConfig = rootConfig;

            SetDefaultCulture(rootConfig);

            m_AppServers = appServers.ToList();

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (!rootConfig.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, null, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
            }

            if (m_GlobalLog.IsDebugEnabled)
                m_GlobalLog.Debug("The Bootstrap has been initialized!");

            m_Initialized = true;
        }
Exemple #34
0
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
                throw new Exception("The server had been initialized already, you cannot initialize it again!");

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            IEnumerable<WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
            {
                var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();

                logFactory = bootstrapLogFactory.ExportFactory.CreateExport<ILogFactory>();

                LogFactory = logFactory;
                m_GlobalLog = logFactory.GetLog(this.GetType().Name);

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                try
                {
                    workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                        m_GlobalLog.Error(e);

                    return false;
                }
            }

            m_AppServers = new List<IWorkItem>(m_Config.Servers.Count());

            IWorkItem serverManager = null;

            //Initialize servers
            foreach (var factoryInfo in workItemFactories)
            {
                IWorkItem appServer = InitializeAndSetupWorkItem(factoryInfo);

                if (appServer == null)
                    return false;

                if (factoryInfo.IsServerManager)
                    serverManager = appServer;
                else if (!(appServer is IsolationAppServer))//No isolation
                {
                    //In isolation mode, cannot check whether is server manager in the factory info loader
                    if (TypeValidator.IsServerManagerType(appServer.GetType()))
                        serverManager = appServer;
                }

                m_AppServers.Add(appServer);
            }

            if (serverManager != null)
                m_ServerManager = serverManager;

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, serverManager, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
            }

            if (m_GlobalLog.IsDebugEnabled)
                m_GlobalLog.Debug("The Bootstrap has been initialized!");

            try
            {
                RegisterRemotingService();
            }
            catch (Exception e)
            {
                if (m_GlobalLog.IsErrorEnabled)
                    m_GlobalLog.Error("Failed to register remoting access service!", e);

                return false;
            }

            m_Initialized = true;

            return true;
        }
Exemple #35
0
        public static ILog GetDefaultLog(this ILogFactory factory)
        {
            var log = factory.GetLog(DefaultLogName);

            return(log);
        }