示例#1
0
 static EventLog()
 {
     if (!DiagELog.SourceExists("16Below"))
     {
         DiagELog.CreateEventSource("16Below", "Application");
     }
 }
示例#2
0
 static EventLog()
 {
     if (!DiagELog.SourceExists("ServUO"))
     {
         DiagELog.CreateEventSource("ServUO", "Application");
     }
 }
示例#3
0
 static EventLog()
 {
     if (!DiagELog.SourceExists("Project1501"))
     {
         DiagELog.CreateEventSource("Project1501", "Application");
     }
 }
示例#4
0
 static EventLog()
 {
     if (!DiagELog.SourceExists(SystemName))
     {
         DiagELog.CreateEventSource(SystemName, "Application");
     }
 }
示例#5
0
        public void WriteEntry(LogEntry entry)
        {
            if (!WindowsEventLog.SourceExists(Source))
            {
                WindowsEventLog.CreateEventSource(Source, log);
            }
            switch (entry.Severity)
            {
            case Severity.Disaster:
                _eventLog.WriteEntry(entry.Message, EventLogEntryType.Error);
                break;

            case Severity.Warning:
                _eventLog.WriteEntry(entry.Message, EventLogEntryType.Warning);
                break;

            case Severity.Information:
                _eventLog.WriteEntry(entry.Message, EventLogEntryType.Information);
                break;
            }
        }
示例#6
0
文件: Exe.cs 项目: kryssb/SySal.NET
        /// <summary>
        /// Set things in motion.
        /// </summary>
        protected void OnStart(string[] args)
        {
            try
            {
                int i;
                if (!EventLog.Exists("Opera"))
                {
                    EventLog.CreateEventSource("OperaDataProcServer", "Opera");
                }
                EventLog.Source = "OperaDataProcServer";
                EventLog.Log    = "Opera";

                System.Configuration.AppSettingsReader asr = new System.Configuration.AppSettingsReader();
                try
                {
                    DBServer   = SySal.OperaDb.OperaDbCredentials.Decode((string)asr.GetValue("DBServer", typeof(string)));
                    DBUserName = SySal.OperaDb.OperaDbCredentials.Decode((string)asr.GetValue("DBUserName", typeof(string)));
                    DBPassword = SySal.OperaDb.OperaDbCredentials.Decode((string)asr.GetValue("DBPassword", typeof(string)));
                }
                catch (Exception x)
                {
                    throw new Exception("Encryption error in credentials.\r\nPlease fill in valid encrypted data (you can use OperaDbGUILogin, for instance), or run the service as the appropriate user.");
                }
                SySal.OperaDb.OperaDbConnection conn = new SySal.OperaDb.OperaDbConnection(DBServer, DBUserName, DBPassword);
                conn.Open();

                IPHostEntry iph   = Dns.Resolve(Dns.GetHostName());
                string []   idstr = new string[iph.Aliases.Length + iph.AddressList.Length];
                idstr[0] = iph.HostName;
                for (i = 0; i < iph.Aliases.Length; i++)
                {
                    idstr[i] = iph.Aliases[i];
                }
                for (i = 0; i < iph.AddressList.Length; i++)
                {
                    idstr[i + iph.Aliases.Length] = iph.AddressList[i].ToString();
                }
                string selstr = "LOWER(TB_MACHINES.ADDRESS)='" + iph.HostName.ToLower() + "'";
                foreach (string s in idstr)
                {
                    selstr += (" OR ADDRESS='" + s + "'");
                }
                DataSet ds = new DataSet();
                SySal.OperaDb.OperaDbDataAdapter da = new SySal.OperaDb.OperaDbDataAdapter("SELECT TB_SITES.ID, TB_SITES.NAME, TB_MACHINES.ID, TB_MACHINES.NAME, TB_MACHINES.ADDRESS FROM TB_SITES INNER JOIN TB_MACHINES ON (TB_MACHINES.ID_SITE = TB_SITES.ID AND TB_MACHINES.ISDATAPROCESSINGSERVER = 1 AND (" + selstr + "))", conn, null);
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count < 1)
                {
                    throw new Exception("Can't find myself in OperaDb registered machines. This service is made unavailable.");
                }
                IdSite         = SySal.OperaDb.Convert.ToInt64(ds.Tables[0].Rows[0][0]);
                SiteName       = ds.Tables[0].Rows[0][1].ToString();
                IdMachine      = SySal.OperaDb.Convert.ToInt64(ds.Tables[0].Rows[0][2]);
                MachineName    = ds.Tables[0].Rows[0][3].ToString();
                MachineAddress = ds.Tables[0].Rows[0][4].ToString();

                object val;
                val = ReadOverride("DPS_MachinePowerClass", conn);
                if (val != System.DBNull.Value)
                {
                    MachinePowerClass = Convert.ToInt32(val.ToString());
                }
                else
                {
                    MachinePowerClass = (int)asr.GetValue("MachinePowerClass", typeof(int));
                }

                val = ReadOverride("DPS_PeakWorkingSetMB", conn);
                if (val != System.DBNull.Value)
                {
                    PeakWorkingSetMB = Convert.ToInt32(val.ToString());
                }
                else
                {
                    PeakWorkingSetMB = (int)asr.GetValue("PeakWorkingSetMB", typeof(int));
                }

                val = ReadOverride("DPS_ResultLiveSeconds", conn);
                if (val != System.DBNull.Value)
                {
                    ResultLiveTime = System.TimeSpan.FromSeconds(Convert.ToInt32(val.ToString()));
                }
                else
                {
                    ResultLiveTime = System.TimeSpan.FromSeconds((int)asr.GetValue("ResultLiveSeconds", typeof(int)));
                }

                val = ReadOverride("DPS_LowPriority", conn);
                if (val != System.DBNull.Value)
                {
                    LowPriority = Convert.ToBoolean(val.ToString());
                }
                else
                {
                    LowPriority = (bool)asr.GetValue("LowPriority", typeof(bool));
                }

                ChannelServices.RegisterChannel(new TcpChannel((int)SySal.DAQSystem.OperaPort.DataProcessingServer));
                DPS = new SySal.DAQSystem.MyDataProcessingServer(EventLog);
                RemotingServices.Marshal(DPS, "DataProcessingServer.rem");
                conn.Close();

                EventLog.WriteEntry("Service starting\r\nThread Priority: " + (LowPriority ? "Below normal" : "Normal") + "\r\nPeak working set (MB): " + PeakWorkingSetMB + "\r\nMachine power class: " + MachinePowerClass + "\r\nSelf-identification yields:\r\nSite: " + SiteName + "\r\nSite Id: " + IdSite + "\r\nMachine: " + MachineName + "\r\nMachine Id: " + IdMachine + "\r\nMachine Address: " + MachineAddress, EventLogEntryType.Information);
            }
            catch (System.Exception x)
            {
                EventLog.WriteEntry("Service startup failure:\n" + x.ToString(), EventLogEntryType.Error);
                throw x;
            }
        }