Пример #1
0
        /// <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);
        }
Пример #2
0
        public void Init()
        {
            try
            {
                if (!_initHasRun)
                {
                    _initHasRun = true;


                    // set system wide severity
                    Logger.Instance.Severity = LogSeverity.Info;

                    var eventLog = new ObserverLogToEventlog();
                    Logger.Instance.Attach(eventLog);

                    var logConsole = new ObserverLogToConsole();
                    Logger.Instance.Attach(logConsole);

                    // send log messages to a file



                    Logger.Instance.Info("Up and running ==> " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    Logger.Instance.Info("Config: " + InsuranceContext.ConnectionString);


                    //var result = CheckForInternetConnection();
                    //if(result == true)
                    LoggedInInfo.InitDb();

                    //else {
                    //    throw new Exception("Internet not connected to your system");
                    //}
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("Init failed: " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
                throw ex;
            }
        }