/// <summary> /// Initializes logging facility with severity level and observer(s). /// Private helper method. /// </summary> private void InitializeLogger() { // Read and assign application wide logging severity string severity = ConfigurationManager.AppSettings.Get("LogSeverity"); SingletonLogger.Instance.Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), severity, true); // Send log messages to database (observer pattern) ILog log = new ObserverLogToDatabase(); SingletonLogger.Instance.Attach(log); // Send log messages to email (observer pattern) string from = "*****@*****.**"; string to = "*****@*****.**"; string subject = "Webmaster: please review"; string body = "email text"; SmtpClient smtpClient = new SmtpClient("mail.yourcompany.com"); log = new ObserverLogToEmail(from, to, subject, body, smtpClient); SingletonLogger.Instance.Attach(log); // Send log messages to a file log = new ObserverLogToFile(@"C:\Temp\DoFactory.log"); SingletonLogger.Instance.Attach(log); // Send log message to event log log = new ObserverLogToEventlog(); SingletonLogger.Instance.Attach(log); }
static void Main() { #region Log init var severity = ConfigurationManager.AppSettings.Get("LogSeverity"); SingletonLogger.Instance.Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), severity, true); ILog log = new ObserverLogToConsole(); SingletonLogger.Instance.Attach(log); log = new ObserverLogToFile("filename"); SingletonLogger.Instance.Attach(log); #endregion Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // Code that runs on application startup // Read and assign application wide logging severity string severity = ConfigurationManager.AppSettings.Get("LogSeverity"); SingletonLogger.Instance.Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), severity, true); // Send log messages to debugger console (output window). // Btw: the attach operation is the Observer pattern. ILog log = new ObserverLogToConsole(); SingletonLogger.Instance.Attach(log); // Send log messages to a file log = new ObserverLogToFile("filename"); SingletonLogger.Instance.Attach(log); ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new SmsService() }; ServiceBase.Run(ServicesToRun); }