protected override void OnStop() { // Signal the timer to stop running. timer.Enabled = false; eventLog.Log(new Event(EVENT_LOG_SOURCE_NAME, DateTime.Now, Event.SeverityLevels.Information, EVENT_LOG_CATEGORY_GENERAL, "Expiration service stopped.")); }
/// <summary> /// Logs an event to the event log. /// </summary> /// <param name="eventToLog">The event to Log.</param> /// <returns>True if the event was logged, false otherwise.</returns> public static bool Log(Event eventToLog) { // It's necessary to sleep to iterate the timestamp so the log will accept the entry. Thread.Sleep(10); return(eventLog.Log(eventToLog)); }
/// <summary> /// Loads configuration data, and readies the service for execution. /// </summary> protected void InitializeService() { // Get the connection string for the database. databaseConnectionString = (new ConfigurationItem(AppDomain.CurrentDomain.BaseDirectory + CONFIG_ITEM_DIRECTORY, DATABASE_CONNECTION_STRING_CONFIGURATION_ITEM_NAME, true)).Value; // Create a SQL Event log instance for logging application events. eventLog = new SqlEventLog(databaseConnectionString, typeof(MSStoredProcedure)); if (eventLog == null) { throw new ApplicationException("Unable to initialize event log."); } eventLog.Log(new Event(EVENT_LOG_SOURCE_NAME, DateTime.Now, Event.SeverityLevels.Information, EVENT_LOG_CATEGORY_GENERAL, "Expiration service started.")); // Read the application's configuration from it's configuration item. ReadApplicationConfig(); // Get the override payload template. string payloadFilePath = AppDomain.CurrentDomain.BaseDirectory + OVERRIDE_PAYLOAD_TEMPLATE_PATH; if (File.Exists(payloadFilePath)) { try { unregisterPayloadTemplate = File.ReadAllAsText(payloadFilePath); eventLog.Log(new Event(EVENT_LOG_SOURCE_NAME, DateTime.Now, Event.SeverityLevels.Information, EVENT_LOG_CATEGORY_GENERAL, "Loaded unregister payload from " + payloadFilePath + " . ")); } catch { eventLog.Log(new Event(EVENT_LOG_SOURCE_NAME, DateTime.Now, Event.SeverityLevels.Error, EVENT_LOG_CATEGORY_GENERAL, "Unable to load unregister payload from " + payloadFilePath + " .")); throw new ApplicationException("Unable to load unregister paylod. Check log for more details."); } } }