// public static bool LoggingInitialized { get; private set; } // // public static bool SettingsProviderInitialized { get; private set; } // /// <summary> // /// Defaults to 2 minutes. // /// </summary> // public static int AppShutdownTimeoutSeconds // { // get // { // string timeout = _settingsProvider.GetSetting(ThisClassName, "AppShutdownTimeoutSeconds", // 120.ToString()); // // return Int32.Parse(timeout); // } // } // private static void LogIPAddress(ILogWriter logWriter) // { // IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName()); // // foreach (IPAddress address in ipHostEntry.AddressList) // { // logWriter.AddEntry(new LogEntry(MessageLevel.Verbose, ThisClassName, address.ToString())); // } // } public static void ShutDown() { // if (!IsRunning) // { // throw new InvalidOperationException("Agent is not running."); // } if (_onShutDown != null) { _onShutDown(); } // WriteShutdownTimeToRegistry(DateTime.Now.ToString()); if (_applicationLog != null) { string agentId = _agentIdentity == null ? "(unknown)" : _agentIdentity.ID; _applicationLog.AddEntry( new LogEntry( MessageLevel.AppLifecycle, ThisClassName, string.Format("Agent {0} shutting down.", agentId))); } StopAllServices(); // ApplicationLog.LogWriters.RemoveAll(w => w is DbLogWriter); }
public static void InitDefault(IApplicationLog log, ISettingsProvider settingsProvider) { InMemoryLogWriter tempWriter = log.LogWriters.OfType <InMemoryLogWriter>().FirstOrDefault(); if (tempWriter != null) { log.LogWriters.Remove(tempWriter); foreach (ILogEntry entry in tempWriter.Entries) { log.AddEntry(entry); } } log.LogFilters.Add(new WhiteSourceLogFilter(settingsProvider)); log.LogFilters.Add(new BlackSourceLogFilter("Recording Polling", settingsProvider)); log.LogFilters.Add(new MessageLevelLogFilter(settingsProvider)); }
public static void Init( IApplicationLog applicationLog, Func <ILogWriter, IApplicationWatchdog> initWatchdog, Func <ILogWriter, IExceptionHandler> initExceptionHandler, Func <ILogWriter, IAgentIdentity> initAgentIdentity, Func <ILogWriter, IAgentIdentity, ISettingsProvider> initSettingsProvider, Action <ISettingsProvider, IApplicationLog, IAgentIdentity> initApplicationLog, Func <IExceptionHandler, ILogWriter, ISettingsProvider, IAgentIdentity, IApplicationWatchdog, IApplicationServiceBus> loadServiceBus, Action onShutDown) { if (applicationLog == null) { throw new ArgumentNullException("applicationLog"); } if (initWatchdog == null) { throw new ArgumentNullException("initWatchdog"); } if (initApplicationLog == null) { throw new ArgumentNullException("initApplicationLog"); } if (initExceptionHandler == null) { throw new ArgumentNullException("initExceptionHandler"); } if (initSettingsProvider == null) { throw new ArgumentNullException("initSettingsProvider"); } if (initAgentIdentity == null) { throw new ArgumentNullException("initAgentIdentity"); } if (onShutDown == null) { throw new ArgumentNullException("onShutDown"); } if (loadServiceBus == null) { throw new ArgumentNullException("loadServiceBus"); } _onShutDown = onShutDown; IApplicationWatchdog watchdog = initWatchdog(applicationLog); watchdog.BeatDog(); _exceptionHandler = initExceptionHandler(applicationLog); _agentIdentity = initAgentIdentity(applicationLog); applicationLog.AddEntry( new LogEntry( MessageLevel.AppLifecycle, ThisClassName, string.Format("Agent {0} started.", _agentIdentity.ID))); _settingsProvider = initSettingsProvider(applicationLog, _agentIdentity); initApplicationLog(_settingsProvider, applicationLog, _agentIdentity); _applicationLog = applicationLog; _serviceBus = loadServiceBus(_exceptionHandler, applicationLog, _settingsProvider, _agentIdentity, watchdog); _settingsProvider.SettingsChanged += SettingsProvider_SettingsChanged; }