protected virtual void DoInitApplication()
        {
            const string FROM = "app.init";

            ConfigAttribute.Apply(this, m_ConfigRoot);

            m_Name = m_ConfigRoot.AttrByName(CONFIG_APP_NAME_ATTR).ValueAsString(GetType().FullName);

            Debugging.DefaultDebugAction = Debugging.ReadDefaultDebugActionFromConfig();
            Debugging.TraceDisabled      = Debugging.ReadTraceDisableFromConfig();

            var node = m_ConfigRoot[CONFIG_LOG_SECTION];

            if (node.Exists)
            {
                try
                {
                    m_Log = FactoryUtils.MakeAndConfigure(node, typeof(LogService)) as ILogImplementation;

                    if (m_Log == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Log made");

                    BeforeLogStart(m_Log);

                    if (m_Log is Service)
                    {
                        if (((Service)m_Log).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Log started, msg times are localized of machine-local time until time source starts");
                        }
                    }
                }
                catch (Exception error)
                {
                    throw new AzosException(StringConsts.APP_LOG_INIT_ERROR + error.ToMessageWithType(), error);
                }
            }

            node = m_ConfigRoot[CONFIG_MODULES_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_Module = FactoryUtils.MakeAndConfigure(node, typeof(HubModule)) as IModuleImplementation;

                    if (m_Module == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Module root made");

                    BeforeModuleStart(m_Module);

                    if (m_Module is Service)
                    {
                        if (((Service)m_Module).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Module root started");
                        }
                    }
                }
                catch (Exception error)
                {
                    throw new AzosException(StringConsts.APP_MODULE_INIT_ERROR + error.ToMessageWithType(), error);
                }
            }

            node = m_ConfigRoot[CONFIG_TIMESOURCE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_TimeSource = FactoryUtils.MakeAndConfigure(node, null) as ITimeSourceImplementation;

                    if (m_TimeSource == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "TimeSource made");

                    BeforeTimeSourceStart(m_TimeSource);

                    if (m_TimeSource is Service)
                    {
                        if (((Service)m_TimeSource).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "TimeSource started");
                        }
                    }

                    WriteLog(MessageType.Info, FROM, "Log msg time is time source-supplied now");

                    m_StartTime = LocalizedTime;
                    WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime));
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_TIMESOURCE_INIT_ERROR + error.ToMessageWithType();
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }
            else
            {
                WriteLog(MessageType.Info, FROM, "Using default time source");

                m_StartTime = LocalizedTime;
                WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime));
            }


            node = m_ConfigRoot[CONFIG_EVENT_TIMER_SECTION];
            //20150827 DKh event timer must allocate even if it is absent in config
            //// if (node.Exists)
            {
                try
                {
                    m_EventTimer = FactoryUtils.MakeAndConfigure(node, typeof(EventTimer)) as IEventTimerImplementation;

                    if (m_EventTimer == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "EventTimer made");

                    BeforeEventTimerStart(m_EventTimer);

                    if (m_EventTimer is Service)
                    {
                        if (((Service)m_EventTimer).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "EventTimer started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_EVENT_TIMER_INIT_ERROR + error.ToMessageWithType();
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }



            node = m_ConfigRoot[CONFIG_SECURITY_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_SecurityManager = FactoryUtils.MakeAndConfigure(node, typeof(ConfigSecurityManager)) as ISecurityManagerImplementation;

                    if (m_SecurityManager == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Security Manager made");

                    BeforeSecurityManagerStart(m_SecurityManager);

                    if (m_SecurityManager is Service)
                    {
                        if (((Service)m_SecurityManager).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Security Manager started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_SECURITY_MANAGER_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }

            try
            {
                Behavior.ApplyConfiguredBehaviors(this, m_ConfigRoot);
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_APPLY_BEHAVIORS_ERROR + error;
                WriteLog(MessageType.Error, FROM, msg, error);
                throw new AzosException(msg, error);
            }


            node = m_ConfigRoot[CONFIG_INSTRUMENTATION_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_Instrumentation = FactoryUtils.MakeAndConfigure(node, typeof(InstrumentationService)) as IInstrumentationImplementation;

                    if (m_Instrumentation == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Instrumentation made");

                    BeforeInstrumentationStart(m_Instrumentation);

                    if (m_Instrumentation is Service)
                    {
                        if (((Service)m_Instrumentation).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Instrumentation started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_INSTRUMENTATION_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }


            node = m_ConfigRoot[CONFIG_DATA_STORE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_DataStore = FactoryUtils.MakeAndConfigure(node) as IDataStoreImplementation;

                    if (m_DataStore == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "DataStore made");


                    BeforeDataStoreStart(m_DataStore);

                    if (m_DataStore is Service)
                    {
                        if (((Service)m_DataStore).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "DataStore started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_DATA_STORE_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }

            node = m_ConfigRoot[CONFIG_OBJECT_STORE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_ObjectStore = FactoryUtils.MakeAndConfigure(node, typeof(ObjectStoreService)) as IObjectStoreImplementation;

                    if (m_ObjectStore == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "ObjectStore made");

                    BeforeObjectStoreStart(m_ObjectStore);

                    if (m_ObjectStore is Service)
                    {
                        if (((Service)m_ObjectStore).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "ObjectStore started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_OBJECT_STORE_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }

            node = m_ConfigRoot[CONFIG_GLUE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_Glue = FactoryUtils.MakeAndConfigure(node, typeof(Azos.Glue.Implementation.GlueService)) as IGlueImplementation;

                    if (m_Glue == null)
                    {
                        throw new AzosException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                                node
                                                .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                                .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Glue made");

                    BeforeGlueStart(m_Glue);

                    if (m_Glue is Service)
                    {
                        if (((Service)m_Glue).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Glue started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_GLUE_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new AzosException(msg, error);
                }
            }
        }
 /// <summary>
 /// Override to prep module implementation i.e. inject modules programmaticaly
 /// </summary>
 protected virtual void BeforeModuleStart(IModuleImplementation logImplementation)
 {
 }