// initializes logging facility with severity level and observer(s).

        private void InitializeLogger()
        {
            // set system wide severity

            Logger.Instance.Severity = LogSeverity.Error;

            // send log messages to debugger console (output window)
            // Note: the attach operation is the Observer pattern

            var logConsole = new ObserverLogToConsole();

            Logger.Instance.Attach(logConsole);

            // also send log messages to email (observer pattern)

            string from       = "*****@*****.**";
            string to         = "*****@*****.**";
            string subject    = "Webmaster: please review";
            string body       = "email text";
            var    smtpClient = new SmtpClient("mail.yourcompany.com");

            var logEmail = new ObserverLogToEmail(from, to, subject, body, smtpClient);

            Logger.Instance.Attach(logEmail);

            // Other log output options (commented out)

            // send log messages to a file

            //var logFile = new ObserverLogToFile(@"C:\Temp\Error.log");
            //Logger.Instance.Attach(logFile);

            // send log message to event log

            //var logEvent = new ObserverLogToEventlog();
            //Logger.Instance.Attach(logEvent);

            // send log messages to database (observer pattern)

            //var logDatabase = new ObserverLogToDatabase();
            //Logger.Instance.Attach(logDatabase);
        }
Esempio n. 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;
            }
        }
Esempio n. 3
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 debugger console (output window).
            // Btw: the attach operation is the Observer pattern.
            ILog log = new ObserverLogToConsole();

            SingletonLogger.Instance.Attach(log);

            // Send log messages to email (observer pattern)
            string from       = "*****@*****.**";
            string to         = "*****@*****.**";
            string subject    = "Webmaster: please review";
            string body       = "email text";
            var    smtpClient = new SmtpClient("mail.yourcompany.com");

            log = new ObserverLogToEmail(from, to, subject, body, smtpClient);
            SingletonLogger.Instance.Attach(log);

            // Other log output options

            //// 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);

            //// Send log messages to database (observer pattern)
            //log = new ObserverLogToDatabase();
            //SingletonLogger.Instance.Attach(log);
        }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            // 將App.config檔裡面DevExpress的設定讀進來
            DevExpress.XtraEditors.WindowsFormsSettings.LoadApplicationSettings();

            #region Log設定

            SingletonLogger.Instance.Severity = (LogSeverity)Enum.Parse(typeof(LogSeverity), SettingDragons.Instance.Setting.Log.LogSeverity, true);

            ILog log = new ObserverLogToDatabase();
            SingletonLogger.Instance.Attach(log);

            log = new ObserverLogToFile("Debug.txt");
            SingletonLogger.Instance.Attach(log);

            log = new ObserverLogToConsole();
            SingletonLogger.Instance.Attach(log);

            #endregion Log設定

            #region GlobalSetting

            SystemStatus.SystemType = SystemType.CI;

            ConnectionInfo connectionInfo = SettingDragons.Instance.GetConnectionInfo(SettingDragons.Instance.Setting.Database.CiUserAp);
            GlobalDaoSetting.Set(connectionInfo);
#if DEBUG
            GlobalInfo.USER_ID       = "I0001";
            GlobalInfo.USER_NAME     = "菲魯特";
            GlobalInfo.USER_DPT_ID   = "J";
            GlobalInfo.USER_DPT_NAME = "資訊規劃部";
#endif

            string reportDirectoryPath = "";

            if (GlobalDaoSetting.GetConnectionInfo.ConnectionName == "CIN2" || Application.StartupPath.IndexOf(@"C:\CI") < 0)
            {
                reportDirectoryPath = Path.Combine(Application.StartupPath, "Report", DateTime.Now.ToString("yyyyMMdd"));
            }
            else
            {
                reportDirectoryPath = Path.Combine(Application.StartupPath, "Excel_Report", DateTime.Now.ToString("yyyyMMdd"));
            }


            string excelTemplateDirectoryPath = "";
            excelTemplateDirectoryPath = Path.Combine(Application.StartupPath, "Excel_Template");

            string batchErrSPDirectoryPath = Path.Combine(Application.StartupPath, "ErrSP");

            Directory.CreateDirectory(reportDirectoryPath);
            GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH = reportDirectoryPath;

            Directory.CreateDirectory(excelTemplateDirectoryPath);
            GlobalInfo.DEFAULT_EXCEL_TEMPLATE_DIRECTORY_PATH = excelTemplateDirectoryPath;

            Directory.CreateDirectory(batchErrSPDirectoryPath);
            GlobalInfo.DEFAULT_BATCH_ErrSP_DIRECTORY_PATH = batchErrSPDirectoryPath;

            #endregion GlobalSetting

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // 如果有傳參數進來
            if (args.Length != 0)
            {
                string userID   = args[0];
                string userName = args[1];
                string txnID    = args[2];
                string txnName  = args[3];

                GlobalInfo.USER_ID   = userID;
                GlobalInfo.USER_NAME = userName;
                if (userID.ToUpper() == GlobalDaoSetting.GetConnectionInfo.ConnectionName)
                {
                    GlobalInfo.USER_DPT_ID = " ";
                }
                else
                {
                    DataTable user = new UPF().ListDataByUserId(userID);
                    GlobalInfo.USER_DPT_ID = user.Rows[0]["UPF_DPT_ID"].AsString();
                }
                Application.Run(new FormMain(txnID, txnName));
            }
            else
            {
#if DEBUG
                Application.Run(new FormMain());
#else
                Application.Run(new FormLogin());
#endif
            }
        }