示例#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);
        }
        private void InitializeLogger()
        {
            // 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);

            // send log messages to a file

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

            Logger.Instance.Attach(logFile);

            // send log messages to database (observer pattern)

            var logDatabase = new ObserverLogToDatabase();

            Logger.Instance.Attach(logDatabase);
        }
示例#3
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
            }
        }