Пример #1
0
        protected override void OnStart(string[] args)
        {
            string logDir = ConfigManager.AppSettings["LogDirectory"].ToString();

            string logFileName = logDir + "ServiceAgentLog_" + DateTime.Now.ToString("MMMMddyyyyhhmmss") + ".xml";
            FileStream fs = new FileStream(logFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamLogger logStream = new StreamLogger(fs, true);
            logStream.IsIDGenerationEnabled = true;
            logStream.IsLineBreakingEnabled = true;
            logStream.IsPreambleEnabled = true;
            logStream.IsExceptionAutoFlushEnabled = true;
            logStream.IsContextEnabled = true;
            logStream.Open();
            try {
                try {
                    logStream.Log("Service started successfully...");
                    //retry the action if it fails to start the thread every 30 seconds.
                    //suspected to throw exception during starting the service if the internet is not yet ready.
                    RetryAction(() => Start(), 1000 * 30);
                } catch (Exception tex) {
                    logStream.Log("SSISPackageExecution using Windows Azure Message Queue");
                    logStream.Log(String.Format("Error in starting service: {0}", tex.Message + Environment.NewLine + tex.StackTrace));
                    if (tex.InnerException != null) {
                        logStream.Log("Inner Exception: " + tex.InnerException.Message.ToString());
                    }
                }
            } catch (Exception ex) {
                logStream.Log(ex);
            } finally {
                logStream.Close();
            }
        }