Exemple #1
0
        public static void TaskWrite(string message, int eventID, int entryid, int appid, EventType etype, Exception ex = null)
        {
            EventLogEntry entry = new EventLogEntry();

            entry.Message         = message;
            entry.Category        = "Task";
            entry.EventDate       = DateTime.Now;
            entry.EventID         = eventID;
            entry.EventType       = etype;
            entry.ApplicationID   = appid;
            entry.ApplicationType = ApplicationType.Tools;
            entry.EntryID         = entryid;
            entry.Ex = ex;
            if (string.IsNullOrEmpty(entry.MachineName))
            {
                entry.MachineName = Environment.MachineName;
            }
            if (!string.IsNullOrEmpty(entry.Message))
            {
                entry.Message = WebHelper.HtmlEncode(entry.Message);
            }
            if (string.IsNullOrEmpty(entry.ApplicationName))
            {
                entry.ApplicationName = "工具";
            }
            Write(entry);
        }
Exemple #2
0
 public static void RemovedCallback(String k, Object v, CacheItemRemovedReason r)
 {
     try
     {
         EventLogEntry entry = v as EventLogEntry;
         if (entry != null && entry.AddTime != entry.LastUpdateTime.Value)
         {
             CommConfig config = CommConfig.GetConfig();
             CommonDataProvider.Instance().WriteEventLogEntry(entry);
         }
     }
     catch { }
 }
Exemple #3
0
        public static void Write(EventLogEntry entry)
        {
            try
            {
                if (entry.ApplicationType != ApplicationType.NoSet && (entry.EventType == EventType.Information || entry.EventType == EventType.Debug))
                {
                    entry.Uniquekey = "";
                    CommConfig config = CommConfig.GetConfig();
                    CommonDataProvider.Instance().WriteEventLogEntry(entry);
                    return;
                }
                string key = string.Empty;
                if (entry.EventType == EventType.Warning)
                {
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}-{2}-{3}-{4}", entry.ApplicationID, entry.EntryID, entry.EventID, (int)entry.EventType, entry.Message.GetHashCode());
                }
                else if (entry.EventType == EventType.Error && entry.Ex != null)
                {
                    key           = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}-{2}-{3}-{4}-{5}", entry.ApplicationID, entry.EntryID, entry.EventID, (int)entry.EventType, entry.Ex.StackTrace.GetHashCode(), entry.Ex.Message.GetHashCode());
                    entry.Message = entry.Ex.Message + "-" + entry.Ex.StackTrace + "\r\n" + entry.Message;
                }
                else
                {
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}", (int)entry.EventType, entry.Message.GetHashCode());
                }

                EventLogEntry oldentry = MangaCache.Get(key) as EventLogEntry;

                if (oldentry != null)
                {
                    oldentry.PCount++;
                    oldentry.LastUpdateTime = DateTime.Now;
                }
                else
                {
                    DateTime time = DateTime.Now;
                    entry.PCount         = 1;
                    entry.Uniquekey      = key;
                    entry.AddTime        = time;
                    entry.LastUpdateTime = time;
                    CommConfig config = CommConfig.GetConfig();
                    CommonDataProvider.Instance().WriteEventLogEntry(entry);
                    entry.PCount = 0;
                    MangaCache.Add(key, entry, 30, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.AboveNormal, new CacheItemRemovedCallback(RemovedCallback));
                }
            }
            catch { }
        }
        /// <summary>
        /// 填充日志信息
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected EventLogEntry PopulateEventLogEntry(IDataReader reader)
        {
            EventLogEntry eventlog = new EventLogEntry();

            eventlog.EntryID         = DataConvert.SafeInt(reader["ID"]);
            eventlog.EventID         = DataConvert.SafeInt(reader["EventID"]);
            eventlog.EventType       = (EventType)(byte)(reader["EventType"]);
            eventlog.Message         = reader["Message"] as string;
            eventlog.Category        = reader["Category"] as string;
            eventlog.MachineName     = reader["MachineName"] as string;
            eventlog.ApplicationName = reader["ApplicationName"] as string;
            eventlog.PCount          = DataConvert.SafeInt(reader["PCount"]);
            eventlog.AddTime         = DataConvert.SafeDate(reader["AddTime"]);
            eventlog.LastUpdateTime  = reader["LastUpdateTime"] as DateTime?;
            eventlog.ApplicationType = (ApplicationType)(byte)(reader["AppType"]);
            return(eventlog);
        }
Exemple #5
0
        public static void JobWrite(string message, int eventID, int appid, EventType etype)
        {
            EventLogEntry entry = new EventLogEntry();

            entry.Message       = message;
            entry.Category      = "Job";
            entry.EventID       = eventID;
            entry.EventType     = etype;
            entry.EventDate     = DateTime.Now;
            entry.ApplicationID = appid;
            if (appid > 0)
            {
                entry.ApplicationType = ApplicationType.Tools;
            }
            else
            {
                entry.ApplicationType = ApplicationType.NoSet;
            }
            entry.EntryID = 0;
            if (string.IsNullOrEmpty(entry.MachineName))
            {
                entry.MachineName = Environment.MachineName;
            }
            if (!string.IsNullOrEmpty(entry.Message))
            {
                entry.Message = WebHelper.HtmlEncode(entry.Message);
            }
            CommConfig config = CommConfig.GetConfig();

            if (!string.IsNullOrEmpty(config.AppSetting["ApplicationName"]))
            {
                entry.ApplicationName = config.AppSetting["ApplicationName"];
            }
            if (!string.IsNullOrEmpty(config.AppSetting["ApplicationID"]))
            {
                entry.ApplicationID = DataConvert.SafeInt(config.AppSetting["ApplicationID"]);
            }
            Write(entry);
        }
 public abstract void WriteEventLogEntry(EventLogEntry log);
 /// <summary>
 /// 写入日志信息
 /// </summary>
 /// <param name="log"></param>
 public override void WriteEventLogEntry(EventLogEntry log)
 {
     try
     {
         string sql = @"INSERT INTO ComOpp_EventLog(
         [Uniquekey]
         ,[EventType]
         ,[EventID]
         ,[Message]
         ,[Category]
         ,[MachineName]
         ,[ApplicationName]
         ,[ApplicationID]
         ,[AppType]
         ,[EntryID]
         ,[PCount]
         ,[AddTime]
         ,[LastUpdateTime]
         )VALUES(
         @Uniquekey
         ,@EventType
         ,@EventID
         ,@Message
         ,@Category
         ,@MachineName
         ,@ApplicationName
         ,@ApplicationID
         ,@AppType
         ,@EntryID
         ,@PCount
         ,@AddTime
         ,@LastUpdateTime
         )";
         SqlParameter[] parameters =
             {
                 new SqlParameter("@Uniquekey", log.Uniquekey),
                 new SqlParameter("@EventType", log.EventType),
                 new SqlParameter("@EventID",log.EventID),
                 new SqlParameter("@Message",log.Message),
                 new SqlParameter("@Category",log.Category),
                 new SqlParameter("@MachineName",log.MachineName),
                 new SqlParameter("@ApplicationName",log.ApplicationName),
                 new SqlParameter("@ApplicationID",log.ApplicationID),
                 new SqlParameter("@AppType",log.ApplicationType),
                 new SqlParameter("@EntryID",log.EntryID),
                 new SqlParameter("@PCount",log.PCount),
                 new SqlParameter("@AddTime",log.AddTime),
                 new SqlParameter("@LastUpdateTime",log.LastUpdateTime)
             };
         SqlHelper.ExecuteNonQuery(_con, CommandType.Text, sql, parameters);
     }
     catch { }
 }
Exemple #8
0
        public static void Write(EventLogEntry entry)
        {
            try
            {
                if (entry.ApplicationType != ApplicationType.NoSet && (entry.EventType == EventType.Information || entry.EventType == EventType.Debug))
                {
                    entry.Uniquekey = "";
                    CommConfig config = CommConfig.GetConfig();
                    CommonDataProvider.Instance().WriteEventLogEntry(entry);
                    return;
                }
                string key = string.Empty;
                if (entry.EventType == EventType.Warning)
                {
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}-{2}-{3}-{4}", entry.ApplicationID, entry.EntryID, entry.EventID, (int)entry.EventType,entry.Message.GetHashCode());
                }
                else if (entry.EventType == EventType.Error && entry.Ex != null)
                {
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}-{2}-{3}-{4}-{5}", entry.ApplicationID, entry.EntryID, entry.EventID, (int)entry.EventType, entry.Ex.StackTrace.GetHashCode(), entry.Ex.Message.GetHashCode());
                    entry.Message = entry.Ex.Message + "-" + entry.Ex.StackTrace + "\r\n" + entry.Message;
                }
                else
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}", (int)entry.EventType, entry.Message.GetHashCode());

                EventLogEntry oldentry = MangaCache.Get(key) as EventLogEntry;

                if (oldentry != null)
                {
                    oldentry.PCount++;
                    oldentry.LastUpdateTime = DateTime.Now;
                }
                else
                {
                    DateTime time = DateTime.Now;
                    entry.PCount = 1;
                    entry.Uniquekey = key;
                    entry.AddTime = time;
                    entry.LastUpdateTime = time;
                    CommConfig config = CommConfig.GetConfig();
                    CommonDataProvider.Instance().WriteEventLogEntry(entry);
                    entry.PCount = 0;
                    MangaCache.Add(key, entry, 30, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.AboveNormal, new CacheItemRemovedCallback(RemovedCallback));
                }

            }
            catch { }
        }
Exemple #9
0
 public static void WebWrite(string message, int eventID, int entryid, int appid, EventType etype, Exception ex = null)
 {
     EventLogEntry entry = new EventLogEntry();
     entry.Message = message;
     entry.Category = "Web";
     entry.EventID = eventID;
     entry.EventDate = DateTime.Now;
     entry.EventType = etype;
     entry.ApplicationID = appid;
     entry.ApplicationType = ApplicationType.WebSite;
     entry.EntryID = entryid;
     entry.Ex = ex;
     if (string.IsNullOrEmpty(entry.MachineName))
     {
         entry.MachineName = Environment.MachineName;
     }
     if (!string.IsNullOrEmpty(entry.Message))
     {
         entry.Message = WebHelper.HtmlEncode(entry.Message);
     }
     if (string.IsNullOrEmpty(entry.ApplicationName))
     {
         entry.ApplicationName = "网站";
     }
     Write(entry);
 }
Exemple #10
0
 public static void JobWrite(string message, int eventID, int appid, EventType etype)
 {
     EventLogEntry entry = new EventLogEntry();
     entry.Message = message;
     entry.Category = "Job";
     entry.EventID = eventID;
     entry.EventType = etype;
     entry.EventDate = DateTime.Now;
     entry.ApplicationID = appid;
     if (appid > 0)
     {
         entry.ApplicationType = ApplicationType.Tools;
     }
     else
     {
         entry.ApplicationType = ApplicationType.NoSet;
     }
     entry.EntryID = 0;
     if (string.IsNullOrEmpty(entry.MachineName))
     {
         entry.MachineName = Environment.MachineName;
     }
     if (!string.IsNullOrEmpty(entry.Message))
     {
         entry.Message = WebHelper.HtmlEncode(entry.Message);
     }
     CommConfig config = CommConfig.GetConfig();
     if (!string.IsNullOrEmpty(config.AppSetting["ApplicationName"]))
     {
         entry.ApplicationName = config.AppSetting["ApplicationName"];
     }
     if (!string.IsNullOrEmpty(config.AppSetting["ApplicationID"]))
     {
         entry.ApplicationID = DataConvert.SafeInt(config.AppSetting["ApplicationID"]);
     }
     Write(entry);
 }
 /// <summary>
 /// 填充日志信息
 /// </summary>
 /// <param name="reader"></param>
 /// <returns></returns>
 protected EventLogEntry PopulateEventLogEntry(IDataReader reader)
 {
     EventLogEntry eventlog = new EventLogEntry();
     eventlog.EntryID = DataConvert.SafeInt(reader["ID"]);
     eventlog.EventID = DataConvert.SafeInt(reader["EventID"]);
     eventlog.EventType = (EventType)(byte)(reader["EventType"]);
     eventlog.Message = reader["Message"] as string;
     eventlog.Category = reader["Category"] as string;
     eventlog.MachineName = reader["MachineName"] as string;
     eventlog.ApplicationName = reader["ApplicationName"] as string;
     eventlog.PCount = DataConvert.SafeInt(reader["PCount"]);
     eventlog.AddTime = DataConvert.SafeDate(reader["AddTime"]);
     eventlog.LastUpdateTime = reader["LastUpdateTime"] as DateTime?;
     eventlog.ApplicationType = (ApplicationType)(byte)(reader["AppType"]);
     return eventlog;
 }
 public abstract void WriteEventLogEntry(EventLogEntry log);